I have the following Json structure:
{ "name": "John", "surname": "Doe", "languages": [ {"language": "english", "level": "3"}, {"language": "french", "level": "1"} ] }
I am using the Play Framework to parse Json data from an HTTP message that was sent using a self-developed REST service. I already know how I can parse the first and last name from the Json data by looking at the documentation, this is done with:
JsonNode json = request().body().asJson(); String name = json.findPath("name").textValue(); String surname = json.findPath("surname").textValue();
Now my question is how can I parse the "languages" of the array in Json data. I found several other posts about this issue, but they all used Scala, which I canβt tear myself away from, so I prefer the Java solution.
I have already tried several things, for example, for example:
List<JsonNode> languages = json.findPath("languages").getElements();
According to the documentation, json.findPath () returns a JsonNode to which you can call the getElements () function, which will return an Iterator JsonNode. But I get a compilation error in getElements: "The getElements () method is undefined for the JsonNode type"
Does anyone know a simple way to parse such an array? thanks in advance
source share