I have a webservice (RestEasy) returning a JSON object containing a List<..> element. I am trying to parse the results in a Javascript for loop. If the List<> element has 2 or more elements, all is well. If the List<> element has only one element, the Javascript loop breaks.
This is because the JSON respresentation actually changes when there is only one element. For example:
{"parent":[{"a":1},{"b":2}]}
works just fine ... but for some reason, the JSON looks like this for one child:
{"parent":{"a":1}}
Note ... that the array indicator [] is missing.
Is that standard JSON? This type of notation forces ugly, unnecessary checks in my javascript for existence or size, etc of an expected array ...
Is this consistent standard practice? Why doesn't JSON return a list of one?
{"parent":[{"a":1}]}
Is this possibly an artifact of my server side and would other server side generators actually build a different JSON representation? I even tried to use dojo.forEach and it works great until it reaches the single element array that unfortunalty, lacks any type of list notation.