jsonpath
jsonpath copied to clipboard
can't deal some strings with numbers and special chars!!!!!
`v := interface{}(nil)
json.Unmarshal([]byte(`{
"welcome":{
"123456":["Good Morning", "Hello World!"]
}
}`), &v)
welcome, err := jsonpath.Get("$.welcome.123456[1]", v)`
`v := interface{}(nil)
json.Unmarshal([]byte(`{
"welcome":{
"product-dv":["Good Morning", "Hello World!"]
}
}`), &v)
welcome, err := jsonpath.Get("$.welcome.product-dv[1]", v)`
I have encountered this and other issues as well.
@liuhongda11
For the first example, jsonpath.Get("$.welcome.123456[1]", v)
, I would propose you use bracket-notation in your path, such as:
jsonpath.Get(`$.welcome["123456"][1]`, v)
I haven't attempted with a hyphen in the index, but I'm guessing that can be solved using bracket-notation as well. Note that I use double-quotes ("
) in the path above. When using single quotes ('
) it seems like the number is treated as a character and thus won't work for numbers with more than one digit.