I like Flexjson and many initializers :
public static void main(String[] args) { Map<String, Object> object = new HashMap<String, Object>() { { put("properties", new Object[] { new HashMap<String, Object>() { { put("someproperty", "aproperty"); put("set of dada", new HashMap<String, Object>() { { put("keyA", "SomeValueA"); put("keyB", "SomeValueB"); put("keyC", "SomeValueC"); } }); } } }); } }; JSONSerializer json = new JSONSerializer(); json.prettyPrint(true); System.out.println(json.deepSerialize(object)); }
leads to:
{ "properties": [ { "someproperty": "aproperty", "set of dada": { "keyA": "SomeValueA", "keyB": "SomeValueB", "keyC": "SomeValueC" } } ] }
source share