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.
$defs is 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.
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
Expected behavior
Returns$.$defs['foo[\'bar'].Returns
$['$defs']['foo[\'bar'].$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.