tidwall / gjson

Get JSON values quickly - JSON parser for Go
MIT License
13.88k stars 841 forks source link

if json path key hava `.` ,how to get the key value ? [ need help ] #352

Closed Lucareful closed 4 months ago

Lucareful commented 4 months ago

Problem

str := `{"code":200,"msg":"","data":{"www.test.com":["hello world"]}}`

I want to get ["hello world"], if i use gjson.Get(str, "data.www.test.com"), it dont work,beacuese . is path,how can i get result ["hello world"]

Greatful!

volans- commented 4 months ago

You have to escape the special characters. See the https://github.com/tidwall/gjson/blob/master/SYNTAX.md#escape-character section of the documentation.

On Fri, Mar 8, 2024, 10:01 Lucareful @.***> wrote:

Problem

str := {"code":200,"msg":"","data":{"www.test.com":["hello world"]}}

I want to get ["hello world"], if i use gjson.Get(str, "data.www.test.com "), it dont work,beacuese . is path,how can i get result ["hello world"]

Greatful!

— Reply to this email directly, view it on GitHub https://github.com/tidwall/gjson/issues/352, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABURVOMDDDER35XR3I6F5OLYXF5AFAVCNFSM6AAAAABEMOSFH6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGE3TKNJYHEYTMMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Lucareful commented 4 months ago

You have to escape the special characters. See the https://github.com/tidwall/gjson/blob/master/SYNTAX.md#escape-character section of the documentation. On Fri, Mar 8, 2024, 10:01 Lucareful @.> wrote: Problem str := {"code":200,"msg":"","data":{"[www.test.com":["hello](http://www.test.com":["hello) world"]}} I want to get ["hello world"], if i use gjson.Get(str, "data.www.test.com "), it dont work,beacuese . is path,how can i get result ["hello world"] Greatful! — Reply to this email directly, view it on GitHub <#352>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABURVOMDDDER35XR3I6F5OLYXF5AFAVCNFSM6AAAAABEMOSFH6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGE3TKNJYHEYTMMQ . You are receiving this because you are subscribed to this thread.Message ID: @.>

thanks !