jsonpath icon indicating copy to clipboard operation
jsonpath copied to clipboard

can't deal some strings with numbers and special chars!!!!!

Open liuhongda11 opened this issue 5 years ago • 3 comments

`v := interface{}(nil)

json.Unmarshal([]byte(`{
	"welcome":{
			"123456":["Good Morning", "Hello World!"]
		}
	}`), &v)

welcome, err := jsonpath.Get("$.welcome.123456[1]", v)`

liuhongda11 avatar Nov 22 '19 14:11 liuhongda11

`v := interface{}(nil)

json.Unmarshal([]byte(`{
	"welcome":{
			"product-dv":["Good Morning", "Hello World!"]
		}
	}`), &v)

welcome, err := jsonpath.Get("$.welcome.product-dv[1]", v)`

liuhongda11 avatar Nov 22 '19 14:11 liuhongda11

I have encountered this and other issues as well.

BorisKozo avatar Jan 05 '20 08:01 BorisKozo

@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.

remnestal avatar Jan 22 '20 14:01 remnestal