0

Possible duplicates: Use Jackson to parse and unnamed array, Parsing JSON with Jackson

I have several files containing unnamed JSON arrays with the following structure:

[ {json stuff}, {json stuff}, ..., {json stuff} ]

However, json stuff varies greatly from file to file, and I already have code that could parse something like "myJSONarray" : [ {json stuff}, {json stuff}, ..., {json stuff} ]. The first step would be something like myJSONarray.get(0) ...Is there any way to use get() in order to get at the contents of the anonymous array?

Community
  • 1
  • 1
Adam
  • 8,752
  • 12
  • 54
  • 96

1 Answers1

0
//read the JSON into myJSONFile (a JsonNode)
....
String s = myJSONFile.toString();
ObjectMapper mapper = new ObjectMapper();

JsonNode actualObj = mapper.readTree(s);
JsonNode blah = actualObj.get(0);

actualObj can be used as if it was a key for the entire JSON file.

Adam
  • 8,752
  • 12
  • 54
  • 96