3

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?

2
  • 3
    I would argue that the second method is more extensible. It is backwards compatible in the event that you'd like to, for example, include some metadata in the object under another member name. The first method would be guaranteed require a breaking change in the event that you wanted to add to the schema. Commented Oct 3, 2015 at 8:19
  • Make sense. So I just don't understand why GitHub, Heroku and Twitter use the first method. Commented Oct 3, 2015 at 12:19

1 Answer 1

1

Array-oriented data has the following advantages:

  • Client-side JavaScript has more methods for arrays than objects
  • No need for root node to simulate a tree structure for a tabular structure

and disadvantages:

  • No namespacing since indexes are numeric
  • JSON.parse fails in client-side JavaScript

Key/Value-oriented data has the following advantages:

  • JSON.parse works in client-side JavaScript
  • Namespacing makes duplicate values easier to disambiguate
  • JSON.stringify works to make simple transformations easier compared to array methods

and disadvantages:

References

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.