I am working with JSON responses from a REST API in Java, but I am looking for a solution that doesn't require creating a Java class (POJO) for each response due to the varying data structures and fields. Is there a more versatile JSON parser in Java that offers a syntax similar to JavaScript's simplicity?
The following JSON represents one example of the many responses from different 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, you can access the value for female like this:
jsonRoot.f4[0].values[0].value
This approach is cleaner than creating numerous Java classes. Do you have any suggestions for a similar solution or a way to avoid generating multiple POJOs?