Which format is better for list in JSON API design, flat array or nested object? -
for list api, such users
, find there 2 common formats. arrays:
// flat array [ { "login": "octocat", "id": 1 ... }, ... ]
github, heroku , twitter use format
vs objects:
{ "results": [ { "login": "octocat", "id": 1 ... }, ... ] }
parse , slack , instagram use format.
which 1 better? how compare these 2 formats?
array-oriented data has following advantages:
- client-side javascript has more methods arrays objects
- no need root node simulate tree structure tabular structure
and disadvantages:
- no namespacing since indexes numeric
json.parse
fails in client-side javascript
key/value-oriented data has following advantages:
json.parse
works in client-side javascript- namespacing makes duplicate values easier disambiguate
json.stringify
works make simple transformations easier compared array methods
and disadvantages:
- it can hard iterate nested hierarchies without library in client-side code
json.parse
in client-side code removes duplicate key names on same level
references
Comments
Post a Comment