Skip to content

Creation of deep nodes #83

Open
Open
@wabrit

Description

@wabrit

It would be useful if JsonPath had the capability to create "deep nodes" rather than just nodes of already existing parents.

For example, provide a method that, given a path e.g. $.x.y.z, a value 10, and a DocumentContext, create the node z with a value 10 allowing for the possibility that x, y do not yet exist. The logic would be

  • If the 1st level node x does not yet exist, create it with an empty object value
  • If the 2nd level node x.y does not yet exist, create it with an empty object value (i.e. create a new property y of x)
  • If the 3rd level node x.y.z does not yet exist, create it with value 10; if it does exist update the value to 10.

It's possible to do this with the existing APIs using an iterative loop to work down the path, DocumentContext.read to test for existence and DocumentContext.put to create, but would be really cool if the API provided such a capability generally.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions