I want to iterate through all nodes of a json object, and write out a plain key-value map, as follows:
{
"name": [{
"first": "John",
"last": "Doe",
"items": [{
"name": "firstitem",
"stock": 12
},
{
"name": "2nditem",
"stock": 23
}
]
}],
"company": "John Company"
}
Should result in:
name-first-1=John
name-last-1=Doe
name-items-name-1-1=firstitem (meaning the list index is always appended at the end of the name)
name-items-name-1-2=2nditem
company=John Company
This is how to get the json string as a json object:
ObjectMapper mapper = new ObjectMapper(); //using jackson
JsonNode root = mapper.readTree(json);
//TODO how loop all nodes and subnodes, and always get their key + value?
But how can I now iterate through all nodes and extract their key and content?