I am parsing JSON responses from the REST API in Java, but I do not want to create a Java class (POJO) for each answer (the answers have different data structures and fields). Is there a more general JSON parser in Java that looks like simple JavaScript syntax?
The JSON below is the result of only one of the many REST endpoints
{
"f1" : "volume",
"f2" : "gender",
"f3" : "days",
"f4" : [{
"id" : "F",
"name" : "female",
"values" : [{
"name" : "September",
"value" : 12
}
]
}, {
"id" : "M",
"name" : "male",
"values" : [{
"name" : "September",
"value" : 11
}
]
}
]
}
In JavaScript, to access a value for a woman:
jsonRoot.f4[0].values[0].value
which is tidier than creating many Java classes. Can you suggest something like this or a way to avoid creating many POJOs?
source
share