Skip to content

API Development JSON Output guide

Ashwin Date edited this page Mar 3, 2017 · 1 revision

To ensure all APIs have a consistent output format, the below JSON structure is proposed. This also makes it easier to build services and apps, since all of the APIs will have consistent output.

com_api output schema v1.0

{
  "err_code" : "", // Send an appropriate application error code when a non-200 HTTP status
  "err_message" : "", // Send an appropriate application error message when a non-200 HTTP status
  "data" : {} // API developers are free to define their data structure here
}

Example response for a list of objects

{
  "err_code" : "", 
  "err_message" : "", 
  "data" : {
    "results": [
    {
      "name": "Category1",
      "identifier": "1",
      "children": [
        {
          "name": "Windows",
          "identifier": "2",
          "children": []
        },
        {
          "name": "Windows Mobile",
          "identifier": "3",
          "children": []
        }
      ]
    },
    {
      "name": "Category2",
      "identifier": "4",
      "children": [
        {
          "name": "SubCategory 1",
          "identifier": "5",
          "children": [
            {
              "name": "Nexus 4",
              "identifier": "6",
              "children": []
            }
          ]
        },
        {
          "name": "SubCategory 2",
          "identifier": "8",
          "children": [
            {
              "name": "ipod",
              "identifier": "9",
              "children": []
            }
          ]
        }
      ]
    }
  ],
  "empty_message":"" // Message to show when the list is empty
}

Example response for a single object, say a user profile

{
  "err_code" : "", 
  "err_message" : "", 
  "data" : {
    "results": {
      "name" : "",
      "bio" : "",
      "avatar" : "",
      "email" : ""
    }
}

Example when there is a validation error

{
  "err_code" : "VAL001", 
  "err_message" : "Invalid Email", 
  "data" : {}
}
Clone this wiki locally