I am developing a RESTful API for a reservation request. You can request a list of numbers. And this is where I really don't know how to design a JSON representation. This is my XML representation:
<?xml version="1.0" encoding="utf-8"?>
<accommodations>
<accommodation>
<name>...</name>
<category>couch</category>
</accommodation>
<accommodation>
<name>...</name>
<category>room</category>
</accommodation>
<accommodations>
My first attempt to convert this to JSON led to this conclusion (1):
{
"0": {
"name": "...",
"category": "couch"
},
"1": {
"name": "...",
"category": "room"
}
}
But when I looked at how other APIs did it, I found something similar to this (2):
[
{
"name": "...",
"category": "couch"
},
{
"name": "...",
"category": "room"
}
]
I know that version 1 is an object, and version 2 is an array.
But which one is better in this case?
source
share