Skip to content

JsonNode.GetPath() doesn't consider character escaping #83547

@gregsdennis

Description

@gregsdennis

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.

Metadata

Metadata

Labels

area-System.Text.Jsonbugin-prThere is an active PR which will close this issue when it is merged

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions