Enhance operation on untyped json through operator overload based on json pointer #1003
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Although it is wonderfull to deserilize json to strong type struct, sometimes it has to deal with untyped json, especially when the input json is too loose or too freely to fit a struct hierarchy. So I devolop a solution for such case.
I summarize the following basic operation on untyped json tree:
/
overload.|
, image asget_or
method.<<
, image as push item to array or object, or overwrite put value to scalar node.|
, pipe to function or closure.All the operators above can be chained as return json pointer, except case 2 which only return primitive scalar value.
Example from that added to
README.md
:And there is also fully documantation example and tests.
Because it is impossible to overload operator for
serde_json::Value
outside the crate, but at most can only to overload operator for new struct for json pointer. So I create this pull request to support json operator natively as well.