Skip to content

JsonPath#set() does not create new paths #256

@ben-manes

Description

@ben-manes
@Test
public void test() {
  String createJson = "{}";
  DocumentContext createContext = JsonPath.parse(createJson).set("$.id", 1);
  System.out.println(createContext.jsonString());

  String updateJson = "{id: 1}";
  DocumentContext updateContext = JsonPath.parse(updateJson).set("$.id", 2);
  System.out.println(updateContext.jsonString());
}
{}
{"id":2}

Is there a way to perform the addition? e.g. set the id if not present.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions