Scenario:
{ "a.b": 1, "a": { "b": 2 } }
Description:
Since "a.b" is a valid key, the . must be escaped before appending to the path, in order to not be confused with "a"."b". A more robust way of dealing with this issue would be to quote the key, as you can also have things like whitespace in the key, or even an empty string as key. A reference approach at https://jqplay.org/s/7sO6XJmPdTZ where I recreated the scenarios using jq.
Code Reference:
https://github.com/apihero-run/json-hero-path/blob/b873f34546c3763b9c78987e504e86b34a295b9c/src/index.ts#L56
Possible Solution:
return new JSONHeroPath(string.concat(`."${key}"`));
Related Issues:
None in this repository, but unfortunately caused one in triggerdotdev/jsonhero-web#98.
Feel free to let me know if there is a better way to solve this (or if my proposed solution will break something), otherwise I will start working on a PR.
Scenario:
{ "a.b": 1, "a": { "b": 2 } }Description:
Since
"a.b"is a valid key, the.must be escaped before appending to the path, in order to not be confused with"a"."b". A more robust way of dealing with this issue would be to quote the key, as you can also have things like whitespace in the key, or even an empty string as key. A reference approach at https://jqplay.org/s/7sO6XJmPdTZ where I recreated the scenarios usingjq.Code Reference:
https://github.com/apihero-run/json-hero-path/blob/b873f34546c3763b9c78987e504e86b34a295b9c/src/index.ts#L56
Possible Solution:
Related Issues:
None in this repository, but unfortunately caused one in triggerdotdev/jsonhero-web#98.
Feel free to let me know if there is a better way to solve this (or if my proposed solution will break something), otherwise I will start working on a PR.