-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
area-System.Text.Jsonbugin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Description
The JsonNode.GetPath() generally does well for C#-valid property names, but any string is valid as a key in JSON, and when a key has characters that need escaping, nothing happens and you get an invalid (unparsable) JSON Path as a result.
Reproduction Steps
JsonNode.Parse("""{"$defs":{"foo['bar":"baz"}}""")["$defs"]["foo['bar"].GetPath();
Expected behavior
Returns $.$defs['foo[\'bar'].
Returns $['$defs']['foo[\'bar'].
- The single quote needs to be escaped.
$defsis not valid as a shorthand property name, so it needs to be in bracketed syntax.
Actual behavior
Returns $.$defs['foo['bar'].
Regression?
Unknown
Known Workarounds
None.
Configuration
Seems to happen everywhere. dotnetfiddle, Linux.
Will update with more details in a comment.
Other information
Originally reported json-everything/json-everything#406.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-System.Text.Jsonbugin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged