I have a nested json structure:
"info": [
{
"name":"Alice",
"phone": [{
"home": "1234567890",
"mobile": "0001112223"
}]
},
{
"name":"Bob",
"phone": [{
"home": "3456789012",
"mobile": "4445556677"
}]
}
]
I'm using jackson. I only want to extract the information about "Bob" and read it into a tree. I do not want to read the whole structure into the tree (I know how to do that) and then extract the information on Bob. I'd like to use the streaming API (JsonParser) to first extract all the information with "Bob" and then make that into a jsontree.
I thought I'd read it into a byte array and then convert that into a tree like so:
JsonToken token = null;
byte[] data;
int i = 0;
while( jParser.nextToken()!=JsonToken.END_ARRAY) {
data[i] = jParser.getByteValue();
i ++;
}
JsonNode node = null;
ObjectMapper objectMapper = new ObjectMapper();
try {
node = objectMapper.readValue(jParser, JsonNode.class);
}
catch(Exception e) {
e.printStackTrace();
}
However, this is not returning the result I want. There's a jsonParse exception so I think this isn't the way to go.