Hello,
I'm trying to change a property in a JSON tree by passing a JsonPointer string and a new property value into my method. For example, in this JSON file:
{
"name" : "John Smith",
"id" : "12345",
"address" : {
"street" : "10 Main Street",
"zip" : "22222"
}
}
I would like to change the zip property by passing "/address/zip" and "55555".
Here is my latest attempt:
ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = mapper.readTree(jsonFile);
JsonPointer pointer = JsonPointer.compile("/address/zip");
JsonPointer head = pointer.head();
JsonPointer last = pointer.last();
JsonNode headNode = rootNode.at(head);
JsonNode lastNode = headNode.at(last);
// Use put() here on the head node using "55555" and the last node name, but nodes don't have names!
Is there another way?
Thanks.