'How to validate Json schema in postman, when the Json has more than one data type

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



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source