Skip to content

ast.Node should support Set variant that sets at any depth, creating objects and arrays as needed #730

Description

@scr-oath

Some use-cases use a combination of gjson and sjson with paths deeper than just a key to alter incoming json data to be fuzzy with a schema - making it "fit" even if clients are at various levels of "compliance" vs correctness, in the spirit of "be generous in what you receive and strict with what you output".

https://github.com/cloudwego/gjson can be useful for the gjson side, but there is no corresponding sjson side. In addition, I'm curious if the ast framework could be good at holding the entire tree and making updates or additions at any level with a more convenient variant of Set, which could create objects and arrays as needed to make a place for the value to sit.

The current state of the module would seemingly require a client to, for every non-leaf key/value do a get and, if !Exists, set to the appropriate type and call either Set or Add as needed for Object v. Array. - while doable, it seems like something that could be made MUCH more convenient and a "pit of success" for clients to use properly/efficiently.

The ultimate hope would be to be able to combinations of get and set on the root structure, without having to re-parse (even lazily) the entire content over and over again, like is needed for gjson/sjson - if updates are made with sjson and return a new []byte then gjson would have to re-read that on subsequent gets to decide further updates/corrections/etc

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions