My original JSON saved on disk: R:\Desktop\alamo\dd
{
"Name": "ABC.com",
"Developer": "Ram Kumar",
"Project List": [
"Compnay: National",
"Compnay: Enterprise",
"Compnay: Alamo"
]
}
My code to remove a particular subNode: "Name
"
public static void main(String[] args) throws IOException {
String locationPath = "R:\\Desktop\\alamo\\dd";
for (File locFile : new File(locationPath).listFiles()){
ObjectMapper mapper = new ObjectMapper();
ObjectNode obj = (ObjectNode) mapper.readTree(locFile);
JsonNode tree1 = mapper.readTree(locFile); //Parse Specific JSON from Rental
if(obj.has("Name")){
obj.remove("Name");
}
System.out.println(obj);
/* if(tree1.has("Name"))
{
((ObjectNode) tree1).remove("Name");
}*/
}
}
Output on console:
{"Developer":"Ram Kumar","Project List":["Compnay: National","Compnay: Enterprise","Compnay: Alamo"]}
The output on console is correct as per modification but when i see my json file it still has Name
subnode.
How to write back??
Thanks