JsonPathKt
JsonPathKt copied to clipboard
Document escaping rules for JsonPath patterns.
I had a key in my JSON that included dots. I found from some other JsonPath libraries that escaping them requires you to include a bracket and single quotes.
val jsonPath = JsonPath.compile("$.['4.0.0']")
// as opposed to
val jsonPath = JsonPath.compile("$.4.0.0")
The docs already mention "Bracket-notated key value accessor for JSON objects" but it was not obvious to me that this should be used for escaping purposes. I'm not aware if there are other escaping rules to be aware of.
It would be nice to add this to the docs. I am willing to open a PR if you think that this is a valid point to add to the docs.
@DSinge what do you think?
@curioustechizen can you point me to the other library that describes escaping them? I feel like this information has less to do with a specific library, and more to do with how JSONPath itself works, so I'd be hesitant to add that info to our documentation. I'm open to seeing what you can come up with though.
Sorry I did not mean that other libraries mention it in their documentation. I meant that there seems to not be agreement among libraries on how to escape dots. For example the answers to this SO question seem to indicate that there are 2 distinct syntaxes for escaping dots.
- The bracket and single-quotes syntax that I described in the issue description
- Another implementation (rest-assured) that omits the brackets
I think the majority of implementations use the first approach, but I'll do some research and see if we should be calling this out.