Can't parse JSON array of arrays to LinkedHashMap in Jackson Can't parse JSON array of arrays to LinkedHashMap in Jackson json json

Can't parse JSON array of arrays to LinkedHashMap in Jackson


Others have suggested the problem, but solutions are bit incomplete. If you need to deal with JSON Objects and Arrays, you can either bind to java.lang.Object, check the type:

Object stuff = objectMapper.readValue(json, Object.class);

and you will get either List or Map (specifically, ArrayList or LinkedHashMap, by default; these defaults can be changed).

Or you can do JSON trees with JsonNode:

JsonNode root = objectMapper.readTree(json);if (root.isObject()) { // JSON Object} else if (root.isArray()) { ...}

latter is often more convenient.

One nice thing is that you can still create regular POJOs out of these, for example:

if (root.isObject()) { MyObject ob = objectMapper.treeToValue(MyObject.class); } // or with Object, use objectMapper.convertValue(ob, MyObject.class)

so you can even have different handling for different types; go back and forth different representations.


The first JSON in your question is a map, or an object. The second is an array. You're not parsing an array, you're parsing a map.

You need to do something like this:

List<MyClass> myObjects = mapper.readValue(jsonInput, new TypeReference<List<MyClass>>(){});

Almost identical question with answer here.


In JSON the {"key": "value"} is Object and the ["this", "that"] is Array.

So, in case when you're receiving the array of objects you should use something like List<Map<Key, Value>>.