Home > Back-end >  How to validate Json schema in postman, when the Json has more than one data type
How to validate Json schema in postman, when the Json has more than one data type

Time:03-08

I am using postman to validate schemas. And the response of an element could be a "number" or "null"

For example:

const schema = {
  "type": "object",
  "properties": {
    "values": {"type": "array",
      "items": [
        {
          "type": "object",
          "properties": {
            "battery_charge_state": {"type": "number"}
          },
          "required": [
            "battery_charge_state"
          ]
        }
      ]
    },
    
  },
}

pm.test("Schema validation", () => {
    pm.response.to.have.jsonSchema(schema);
});

This "battery_charge_state" sometimes could be "null"

How can I validate both scenarios in postman?

Regards

CodePudding user response:

You can do this to handle situation that value can be multiple data types.

"battery_charge_state": {"type": ["number", null]}
  • Related