Harshit
Harshit

Reputation: 721

Resource id as key name in JSON response

Is it recommended that I use a resource id (eg. student id/class id) as a key name in a JSON response of a REST API.

eg.

{
  "code": 0,
  "message": "success",
  "data": {
    "class_details": {
      "123": {
        "student_name": "Abc",
        "performance": [
          {
            "date": "2015-03-26 14:56:19",
            "marks": "98",
            "quiz_id":1
          },
          {
            "date": "2015-03-21 14:56:19",
            "marks": "92",
            "quiz_id":2
          }
        ]
      }
    }
  }
}

Here 123 is the student id.

Upvotes: 0

Views: 296

Answers (1)

Ekansh Rastogi
Ekansh Rastogi

Reputation: 2536

@Harshit i hope this will answer your question

Is it recommended that I use a resource id (eg. student id/class id) as a key name in a JSON response of a REST API.

{
  "code": 0,
  "message": "success",
  "data": {
    "**1546**": {
      "**123**": {
        "student_name": "Abc",
        "**12456**": [
          {
            "date": "2015-03-26 14:56:19",
            "marks": "98",
            "quiz_id":1
          },
          {
            "date": "2015-03-21 14:56:19",
            "marks": "92",
            "quiz_id":2
          }
        ]
      }
    }
  }
}

If you can judge what does the 1546, 123, represents, they you can go with this.

But incase you cannot judge this, this is a bad approach. Any one else other then you or even you, if cannot judge a key in a json then this is practically a bad practice.

Upvotes: 1

Related Questions