I am a novice in Java and I am looking a way to transform Json like in this is example.
I do not know json array, mapper or use List will be more useful for me
Here is the example:
Document received:
{
"data1": "A",
"data2": "B",
"data3": "C",
"data4": [{
"subdata": [{
"subsubdata": "mam"
},
{
"subsubdata": "mom"
},
{
"subsubdata": "mim"
}]
}
}
Document transformed:
{ //data transformed
"data1": "A",
"data2": "B",
"data3": "C",
"data4": {
"subdata": {
"subsubdata": "mam"
}
}
},
{
"data1": "A",
"data2": "B",
"data3": "C",
"data4": {
"subdata": {
{
"subsubdata": "mom"
}
}
}
},
{
"data1": "A",
"data2": "B",
"data3": "C",
"data4": {
"subdata": {
{
"subsubdata": "mim"
}
}
}
}
Give a try to Jackson.
With the ObjectMapper class you can transform a Json in a nested Map<String, Object> collection.
ObjectMapper mapper = new ObjectMapper();
TypeReference<Map<String,Object>> typeRef = new TypeReference<Map<String,Object>>() {};
Map<String, Object> rs = mapper.readValue(myJsonString, typeRef);