-
Notifications
You must be signed in to change notification settings - Fork 860
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
Accessing key with periods in it #333
Comments
@rowsimms42 did you escape the periods? See https://github.com/tidwall/gjson/blob/master/SYNTAX.md#escape-character |
that would only work if I rebuilt the key. I am matching keys in two objects, and am looping through one object and calling "otherObj.Get(key)" |
@rowsimms42 got it. I've never used it and I'm not sure if it's meant to be part of the public API, but there is an |
This commit adds the Escape function for escaping a path component, making it possible to directly querying keys that have special characters like dots. ``` json := `{ "user":{ "first.name": "Janet", "last.name": "Prichard" } }` user := gjson.Get(json, "user") println(user.Get(gjson.Escape("first.name")).String()) println(user.Get(gjson.Escape("last.name")).String()) // Output: // Janet // Prichard ``` See #333
I just exposed the otherObj.Get(gjson.Escape(key)) |
thank you! |
No problem and thanks @volans- for finding that function. I forgot it existed. |
Having keys in the JSON that contain periods will cause incorrect results when using the "Get" function. It would be nice if you could provide the path as Get(key1, key2) instead of as a combined string, or if there were simply a "GetKey" function that considered the passed in string to be the key instead of potentially a path.
The text was updated successfully, but these errors were encountered: