Parse distinct JSON answers in Java without utilising POJO classes.

terry73

New member
I'm using Java to parse JSON replies from REST APIs, but I don't want to generate a Java class (POJO) for each response (responses have different data structures and fields). Is there a more general JSON parser in Java, equivalent to the simple syntax of JavaScript?

The JSON below is the output of one of several REST endpoints.

JavaScript:
{
    "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 the value for female:

JavaScript:
jsonRoot.f4[0].values[0].value

this is preferable to having to write multiple Java classes. Can you recommend something similar or a technique to prevent producing a large number of POJOs?