Marcono1234 / struson

Streaming JSON reader and writer written in Rust
https://crates.io/crates/struson
Apache License 2.0
56 stars 5 forks source link

Support JSON Pointer (RFC 6901) #6

Closed Marcono1234 closed 1 year ago

Marcono1234 commented 1 year ago

Problem solved by the enhancement

Support seeking to a path specified by a JSON Pointer (RFC 6901)

Enhancement description

Add two methods for parsing a JSON Pointer, one for the JSON variant, one for the URI variant. For example:

The result should be a current Struson JsonPath (i.e. [JsonPathPiece]). Maybe also consider renaming that to JsonPointer?

There would be the following deviations from the JSON Pointer specification (have to be documented):

Possibly also consider supporting Relative JSON Pointer.

Alternatives / workarounds

Instead support parsing JSONPath, however the problems are that:

Marcono1234 commented 1 year ago

The JSON Pointer specification unfortunately creates ambiguity regarding whether a number (or -) is an object member name or an array index. This cannot be determined from the JSON Pointer and only be decided when evaluating the JSON Pointer against JSON data.

This prevents integrating it with the existing JsonPathPiece since that strictly differentiates between member names and array indices. Also this ambiguity could be error-prone to some extent because it can point to a JSON value even if the JSON data has an unexpected or incorrect structure, maybe that has some security impact.

So for now I think the json_path! macro of Struson is a good and concise enough alternative, and I am not planning to support JSON Pointer.