For list API, such as Users, I find that there are two common formats. Arrays:
// flat array
[
{
"login": "octocat",
"id": 1
...
},
...
]
GitHub, Heroku and Twitter use this format
VS Objects:
{
"results": [
{
"login": "octocat",
"id": 1
...
},
...
]
}
Parse and Slack and instagram use this format.
Which one is better? How to compare these two formats?
Array-oriented data has the following advantages:
and disadvantages:
JSON.parse fails in client-side JavaScriptKey/Value-oriented data has the following advantages:
JSON.parse works in client-side JavaScriptJSON.stringify works to make simple transformations easier compared to array methodsand disadvantages:
JSON.parse in client-side code removes duplicate key names on the same levelReferences
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With