0

How do I build my own json schema to validate the json coming back from an api is the same structure? I have this sample JSON

{
  "httpStatus": 200,
  "httpStatusMessage": "success",
  "timestamp": "2020-11-11T19:32:45",
  "response": {
    "header": {
      "SchoolId": 10006,
      "SchoolName": "Naples"
    },
    "body": {
      "dataProviders": [
        {
          "dataProviderId": 14,
          "students": [
            {
              "studentId": 1000611000,
              "driverGrade": "Junior",
              "firstName": "Authur",
              "lastName": "Boccuto"
            },
            {
              "studentId": 1000611001,
              "studentGrade": "Senior",
              "firstName": "Antwan",
              "lastName": "Carter"
            }
          ]
        }
      ]
    }
  }
}

At times it can come in with a different structure and I need to build my own json schema to validate that it's the same before manipulating the json data. How do I build my own schema to make sure that it has a valid structure?

  • Not related to your question: what's the point of returning HTTP status code and reason phrase in the response body? Their place is in the header. A success request should return `200 OK` while a request that cannot be processed because of its content or errors should return `400 Bad Request` or `404 Not Found` or whatever is appropriate. Do not answer to all requests with `200 OK`! Use HTTP as it has been designed. Oh, I forgot, read about JSON schema on (where else?) https://json-schema.org. – axiac Dec 04 '20 at 20:40
  • 1
    @axiac I asked that same question. They always send the status back. – pass_the_kavasier Dec 04 '20 at 20:42

0 Answers0