Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is an outer array valid JSON for a REST api?

When using MongoDB with Mongoskin in a Node.js webb app I can run .find() on a collection to fetch all its document. The result is a mongodb cursor. This cursor is then converted to an Array with the cursors .toArray() method.

[
  {
    _id: "53ea101656cb0c0407306405",
    key: "value", 
    ...
  }, 
  {
    _id: "53ea101656cb0c0407306405",
    key: "value", 
    ...
  },
  ...
]

But is this a valid JSON output for a REST Api?... or should i convert the outer array to an object? Maybe it doesn't matter?

like image 369
Anders Östman Avatar asked Aug 12 '14 13:08

Anders Östman


1 Answers

It is valid JSON, assuming you put quotes around your keys. REST does not specify the format that a JSON response must use, so do whatever is right for your application.

like image 101
Eric Stein Avatar answered Oct 06 '22 12:10

Eric Stein