you can try

you should modify the file path

ObjectMapper mapper = new ObjectMapper();
ObjectNode nodes = mapper.readValue(new File("D:\\test.txt"), 
ObjectNode.class);
nodes.with("addressDetails").put("pinCode", "414141");
mapper.writer().writeValue(new File("D:\\test.txt"), nodes);
Answer from nan lin on Stack Overflow
🌐
Sourceforge
weka.sourceforge.io › doc.dev › weka › core › json › JSONNode.html
JSONNode
public JSONNode addPrimitive(java.lang.String name, java.lang.Boolean value) Adds a key-value child to the object. Parameters: name - the name of the pair · value - the value · Returns: the new node, or null if none added · public JSONNode addPrimitive(java.lang.String name, java.lang.Integer ...
Discussions

json - How to modify JsonNode in Java? - Stack Overflow
Releases Keep up-to-date on features we add to Stack Overflow and Stack Internal. ... Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I need to change a JSON attribute's value in Java, I can get the value properly but I couldn't modify the JSON. ... JsonNode ... More on stackoverflow.com
🌐 stackoverflow.com
java - Getting the values of a specific key from JsonNode - Stack Overflow
Cannot invoke "com.fasterxml.j....databind.JsonNode.get(int)" is null ... Expected output is [wikidata.org/entity/Q42442324, wikidata.org/entity/Q42442324, Kiisu Miisu, wikidata.org/entity/Q43260736, wikidata.org/prop/direct/P21, Paddles] ... You can use elements() method and check if value key exist then add the value ... More on stackoverflow.com
🌐 stackoverflow.com
Give Ability to Replace existing Key with New Key and KEEP SAME ORDER as existing key
Is your feature request related to a problem? Please describe. I know JSON Is key is order less according to speciation but we are using JSON for diff and order is very important when doing diff. H... More on github.com
🌐 github.com
5
December 14, 2021
json - how to create insert new nodes in JsonNode? - Stack Overflow
with this node, how do I then add key value pairs within so that I can construct this new node with the new values? What I read in http://www.cowtowncoder.com/blog/archives/2011/08/entry_460.html mentioned about using ... But looking at the APIs for Jackson's JsonNode (v1.8) does not show any ... More on stackoverflow.com
🌐 stackoverflow.com
February 26, 2014
🌐
Baeldung
baeldung.com › home › json › jackson › get all the keys in a json string using jsonnode
Get all the Keys in a JSON String Using JsonNode | Baeldung
May 11, 2024 - If yes, we’ll traverse the value object as well to fetch inner nodes. As a result, we’ll get all the key names present in JSON: [Name, Age, BookInterests, Book, Author, Book, Author, FoodInterests, Breakfast, Bread, Beverage, Sandwich, Beverage] In the above example, we can also use the fields() method of the JsonNode ...
🌐
Apps Developer Blog
appsdeveloperblog.com › home › java › java json › modify jsonnode with java jackson
Modify JsonNode with Java Jackson - Apps Developer Blog
August 12, 2022 - Let’s create an empty JsonNode and add a field to it. class Test { public static void main(String[] args) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.createObjectNode(); ((ObjectNode) jsonNode).put("key1", "value1"); System.out.println(jsonNode.toPrettyString()); } } Output: { “key1” : “value1” } Now let’s add a field that represents a User object: public static void main(String[] args) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.createObjectNode(); ((ObjectNode) json
🌐
Jenkov
jenkov.com › tutorials › java-json › jackson-jsonnode.html
Jackson JsonNode
Again, just imagine that the readJsonIntoJsonNode() produces some JsonNode object which we would like to set as child on the ObjectNode parent object. The ObjectNode class also has a set of methods that enables you to put (set) primitive values for fields. This is easier than trying to convert a primitive value to a JsonNode and set it with set().
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.text.json.nodes.jsonobject.add
JsonObject.Add Method (System.Text.Json.Nodes) | Microsoft Learn
public: virtual void Add(System::Collections::Generic::KeyValuePair<System::String ^, System::Text::Json::Nodes::JsonNode ^> property);
Find elsewhere
🌐
GitHub
gist.github.com › ucheng › 3134548
Add or Update Json field value · GitHub
Add or Update Json field value. GitHub Gist: instantly share code, notes, and snippets.
🌐
Baeldung
baeldung.com › home › json › jackson › working with tree model nodes in jackson
Working with Tree Model Nodes in Jackson | Baeldung
January 8, 2024 - We’ll use JsonNode for various conversions as well as adding, modifying, and removing nodes.
Top answer
1 of 2
2

You can use elements() method and check if value key exist then add the value to list.

Smaple code

ObjectMapper mapper = new ObjectMapper();
JsonNode jsonNode = mapper.readTree(data);

List<String> values = new ArrayList<>();
jsonNode.forEach(jsonObject -> jsonObject.elements().forEachRemaining(valueNode -> {
    if(valueNode.has("value"))
        values.add(valueNode.get("value").asText());
}));
System.out.println(values);

Output:

[http://www.wikidata.org/entity/Q42442324, http://www.wikidata.org/prop/direct/P21, Kiisu Miisu, http://www.wikidata.org/entity/Q43260736, http://www.wikidata.org/prop/direct/P21, Paddles]
2 of 2
0

Here is the solution by "Josson & Jossons". I list 2 more examples with condition filtering.

https://github.com/octomix/josson

implementation 'com.octomix.josson:josson:1.3.22'

---------------------------------------------

Josson josson = Josson.fromJsonString(
    "[" +
    "  {" +
    "    \"item\": {" +
    "      \"type\": \"uri\", \"value\": \"http://www.wikidata.org/entity/Q42442324\"" +
    "    }," +
    "    \"prop\": {" +
    "      \"type\": \"uri\", \"value\": \"http://www.wikidata.org/prop/direct/P21\"" +
    "    }," +
    "    \"itemLabel\": {" +
    "      \"xml:lang\": \"en\", \"type\": \"literal\", \"value\": \"Kiisu Miisu\"" +
    "    }" +
    "  }," +
    "  {" +
    "    \"item\": {" +
    "      \"type\": \"uri\", \"value\": \"http://www.wikidata.org/entity/Q43260736\"" +
    "    }," +
    "    \"prop\": {" +
    "      \"type\": \"uri\", \"value\": \"http://www.wikidata.org/prop/direct/P21\"" +
    "    }," +
    "    \"itemLabel\": {" +
    "      \"xml:lang\": \"en\", \"type\": \"literal\", \"value\": \"Paddles\"" +
    "    }" +
    "  }" +
    "]");

JsonNode node = josson.getNode("*.value");
System.out.println("1.\n" + node.toPrettyString());

node = josson.getNode("~'^item.*'.value");
System.out.println("2.\n" + node.toPrettyString());

node = josson.getNode("*[value.type='uri']*.value");
System.out.println("3.\n" + node.toPrettyString());

Output:

1.
[ "http://www.wikidata.org/entity/Q42442324", "http://www.wikidata.org/prop/direct/P21", "Kiisu Miisu", "http://www.wikidata.org/entity/Q43260736", "http://www.wikidata.org/prop/direct/P21", "Paddles" ]
2.
[ "http://www.wikidata.org/entity/Q42442324", "Kiisu Miisu", "http://www.wikidata.org/entity/Q43260736", "Paddles" ]
3.
[ "http://www.wikidata.org/entity/Q42442324", "http://www.wikidata.org/prop/direct/P21", "http://www.wikidata.org/entity/Q43260736", "http://www.wikidata.org/prop/direct/P21" ]
🌐
Tabnine
tabnine.com › home page › code › java › com.fasterxml.jackson.databind.node.objectnode
com.fasterxml.jackson.databind.node.ObjectNode.putAll java code examples | Tabnine
public JsonNode toJsonNode() { final ObjectNode ret = FACTORY.objectNode() .put("domain", domain.toString()).put("keyword", keyword) .put("message", message); if (fatal) ret.put("fatal", true); ret.putAll(info); return ret; } origin: org.kitchen-eel/json-schema-validator · .put("path", ptr.toString()); node.putAll((ObjectNode) msg.toJsonNode()); ret.add(node); origin: com.qubole.qds-sdk-java/qds-sdk-java ·
🌐
GitHub
github.com › FasterXML › jackson-databind › issues › 3348
Give Ability to Replace existing Key with New Key and KEEP SAME ORDER as existing key · Issue #3348 · FasterXML/jackson-databind
December 14, 2021 - Now, If I wanted to KEEP the key order and replace ‘key and value’ at the position of "2" but keep the position. ((ObjectNode)JsonNode root).remove("2","v5"); ((ObjectNode)JsonNode root).put("22","v6"); I will end up with:
Author   bmistry13
🌐
Tabnine
tabnine.com › home page › code › java › org.codehaus.jackson.jsonnode
org.codehaus.jackson.JsonNode.getFields java code examples | Tabnine
private Map<String, Set<String>> ... String key = oneEntry.getKey(); Set<String> valueSet = new HashSet<String>(); JsonNode valueNodes = oneEntry.getValue(); if ( valueNodes != null ) { for ( JsonNode oneValue : valueNodes ) { if ( oneValue ...
🌐
Fasterxml
fasterxml.github.io › jackson-databind › javadoc › 2.7 › com › fasterxml › jackson › databind › JsonNode.html
JsonNode (jackson-databind 2.7.0 API)
Method that can be called on Object ... create, add and return such Array node. If the node method is called on is not Object node, or if property exists and has value that is not Array node, UnsupportedOperationException is thrown · public boolean equals(Comparator<JsonNode> comparator, ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.text.json.nodes.jsonobject.system-collections-generic-idictionary-system-string-system-text-json-nodes-jsonnode--keys
JsonObject.IDictionary<String,JsonNode>.Keys Property (System.Text.Json.Nodes) | Microsoft Learn
property System::Collections::Generic::ICollection<System::String ^> ^ System::Collections::Generic::IDictionary<System::String,System::Text::Json::Nodes::JsonNode>::Keys { System::Collections::Generic::ICollection<System::String ^> ^ get(); };
🌐
I-harness
code.i-harness.com › en › q › af87f4
add from - how to create insert new nodes in JsonNode? - CODE Q&A Solved
You need to get ObjectNode type object in order to set values. Take a look at this ... Use ObjectMapper#convertValue method to covert object to a JsonNode instance. Here is an example: public class JacksonConvert { public static void main(String[] args) { final ObjectMapper mapper = new ...