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:

references


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -