Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
liuhongda11 opened this issue Nov 22, 2019 · 3 comments
Open

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

liuhongda11 opened this issue Nov 22, 2019 · 3 comments

Comments

@liuhongda11
Copy link

`v := interface{}(nil)

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

welcome, err := jsonpath.Get("$.welcome.123456[1]", v)`
@liuhongda11
Copy link
Author

`v := interface{}(nil)

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

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

@BorisKozo
Copy link

I have encountered this and other issues as well.

@remnestal
Copy link

remnestal commented Jan 22, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants