Add new key value to json node in java -


i have json file :

{    "id":1,    "name":"abc",    "addressdetails":       {         "city":"newyork"       } } 

i wanted add 1 more key-value ("pincode" : "414141") node 'addressdetails'.

i tried using :

objectmapper mapper = new objectmapper(); jsonnode root = mapper.readtree(new file("d://test.json")); objectnode node = mapper.createobjectnode(); node.with("addressdetails").put("pincode", "414141");  

but it's not getting added, there way can ?

you can try

you should modify 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); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -