There are different JSON output format for Solr NamedList, as said in JSON Response Writer, and org.apache.solr.response.JSONWriter.
We can controls the output format of NamedLists by parameter json.nl, its value van be flat, map, arrarr, arrmap.
We can check its output by running test case: org.apache.solr.request.JSONWriterTest.testJSON(): use different value for json.nl.
Basically when json.nl=flat, the response would be like: [name1,val1, name2,val2], when json.nl=map, the response would be like: [name1:val1, name2:val2], when json.nl=arr, the response would be like: [[name1,val1], [name2, val2]], when json.nl=arrmap, the response would be like: [{name1:val1}, {name2:val2}].
If not specified, it would use flat mode.
Usually we should use json.nl=map, so client code can easily parse the response and convert it to javascript object.
We can specify default json.nl value in solrconfig.xml when we declare our request handler: in default section or in invariants section if we don't want user to change it.
Another option is in our code, we can use subclass of NamedList: SimpleOrderedMap. It will use map mode as the JSON output.
We can controls the output format of NamedLists by parameter json.nl, its value van be flat, map, arrarr, arrmap.
We can check its output by running test case: org.apache.solr.request.JSONWriterTest.testJSON(): use different value for json.nl.
Basically when json.nl=flat, the response would be like: [name1,val1, name2,val2], when json.nl=map, the response would be like: [name1:val1, name2:val2], when json.nl=arr, the response would be like: [[name1,val1], [name2, val2]], when json.nl=arrmap, the response would be like: [{name1:val1}, {name2:val2}].
If not specified, it would use flat mode.
Usually we should use json.nl=map, so client code can easily parse the response and convert it to javascript object.
We can specify default json.nl value in solrconfig.xml when we declare our request handler: in default section or in invariants section if we don't want user to change it.
Another option is in our code, we can use subclass of NamedList: SimpleOrderedMap. It will use map mode as the JSON output.
org.apache.solr.response.JSONWriter.writeNamedList(String, NamedList) public void writeNamedList(String name, NamedList val) throws IOException { if (val instanceof SimpleOrderedMap) { writeNamedListAsMapWithDups(name,val); } else if (namedListStyle==JSON_NL_FLAT) { writeNamedListAsFlat(name,val); } else if (namedListStyle==JSON_NL_MAP){ writeNamedListAsMapWithDups(name,val); } else if (namedListStyle==JSON_NL_ARROFARR) { writeNamedListAsArrArr(name,val); } else if (namedListStyle==JSON_NL_ARROFMAP) { writeNamedListAsArrMap(name,val); } }