The issue is to decided the trade offs between following notations:
JSON based:
\"users\": {
\"id1\": {
\"id\": \"id1\",
On the server side, Arrays are stored as simple Lists: ArrayList
, while Objects are either stored as maps: HashMap
or, mostly, as Java Objects.
In order to convert Java Entities to and from JSON, you can take a look at the Jackson project which does all that for you.
I wouldn't worry about any performance differences between those two variants. It's more important to have an understandable, semantic API, so you should base your desicion on the business case rather than performance.
Looking at your example, I think an Array
is the better approach, since you want to return a list of users which are all equal. Sending the id twice makes no sense imho and increases the amount of data that has to be transmitted.
Furthermore, since Arrays
are much simpler to store and to iterate in Java, they should also provide better performance than Objects.
Some general differences: