Skip to content

Need better handling of JSON keys #4

@Kit-p

Description

@Kit-p

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions