JsonPathKt icon indicating copy to clipboard operation
JsonPathKt copied to clipboard

Document escaping rules for JsonPath patterns.

Open curioustechizen opened this issue 1 year ago • 4 comments

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.

curioustechizen avatar Jan 15 '24 13:01 curioustechizen

@DSinge what do you think?

eygraber avatar Jan 15 '24 13:01 eygraber

@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.

eygraber avatar Jan 16 '24 18:01 eygraber

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.

  1. The bracket and single-quotes syntax that I described in the issue description
  2. Another implementation (rest-assured) that omits the brackets

curioustechizen avatar Jan 18 '24 10:01 curioustechizen

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.

eygraber avatar Jan 18 '24 13:01 eygraber