Home > database >  How to validate property field which is UUID in json schema?
How to validate property field which is UUID in json schema?

Time:02-19

{
"status": 200,
"id" : "123e4567-e89b-12d3-a456-426655440000",
"shop": {
    "c73bcdcc-2669-4bf6-81d3-e4ae73fb11fd": {
        "123e4567-e89b-12d3-a456-426655443210": {
            "quantity": {
                "value": 10
                },
        },
        "123e4567-e89b-12d3-a456-426655443211": {
            "quantity": {
                "value": 20
           }
       }
    }
}

This is my json response. I want to validate the fields "c73bcdcc-2669-4bf6-81d3-e4ae73fb11fd" , "123e4567-e89b-12d3-a456-426655443210" and "123e4567-e89b-12d3-a456-426655443211", which are uniquely generated every time whenever hits the endpoint.

CodePudding user response:

To validate in JSON schema that a string conforms to a regular expression pattern use { "type": "string", "pattern": "\b[0-9a-f]{8}\b-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-\b[0-9a-f]{12}\b" }

The concrete pattern is adapted from the question Viewes in JSONBuddy

  • Related