Time-stamp json schema

this is the time-stamp “2024-01-09T06:15:28.384000”
I have used the following code in json Schema


"timestamp": {
                    "type": "string",
                    "format": "date-time"
                },

But it’s not working, I keep on getting the error data validation

Hey @satellite-pilot-5611 :wave:

Can you share the full schema and and example of the response body that it’s validating against?

Is this is only part that isn’t working as expected? Has it ever worked for you?


I just created a basic check using the Postman Echo endpoint:

Using the following schema structure (Yours would be different) for that response worked.

pm.test("Validate timestamp property in the response", function () {
  var schema = {
    type: "object",
    properties: {
      data: {
        type: "object",
        properties: {
          timestamp: {
            type: "string",
            format: "date-time"
          }
        },
        required: ["timestamp"]
      }
    },
    required: ["data"]
  };

  pm.response.to.have.jsonSchema(schema);
});

I ensured it was failing by changing the format of the timestamp value so it would break the validation example in the JSONSchema docs.

1 Like

yes that’s the only part that’s not working. I saw it in a tutorial by @vdespa.
It worked there.

That’s the basic schema,

data:{
    "timestamp": {
                    "type": "string",
                    "format": "date-time"
                },

}

I think there is the problem of data-format coming from the response. Anyways thanks for the response.

I’m not sure what tutorial that would have been and i’m guessing that @vdespa would have been using an endpoint that returns a different response structure.

I updated my message to show a basic example of this using the Postman Echo service.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.