Open rowsimms42 opened 1 year ago
@rowsimms42 did you escape the periods? See https://github.com/tidwall/gjson/blob/master/SYNTAX.md#escape-character
@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 escapeComp
function that seems to just do what you need, so basically calling it on the key
you are passing o otherObj
to get it properly escaped.
Again, it might be meant to be internal use only and I can't guarantee it will not be renamed/changed in later releases. You'll have to check with @tidwall.
I just exposed the escapeComp
as Escape
.
otherObj.Get(gjson.Escape(key))
I just exposed the
escapeComp
asEscape
.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.