Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

595
Views
How to validate property field which is UUID in json schema?
   {
  "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.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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 Searching for UUIDs in text with regex see there for more details.

To validate UUID in particular, you may use format in JSON schema, which provides built-in support for the UUID syntax: { "type": "string", "format": "uuid" }

See https://json-schema.org/understanding-json-schema/reference/string.html

over 4 years ago · Santiago Trujillo Report

0

You need "patternProperties":

{ 
  "$schema":"http://json-schema.org/draft-07/schema#",
  "type":"object",
  "properties": {
    "shop":{
      "type":"object",
      "additionalProperties":false,
      "patternProperties":{
        "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}": {
          "type":"object",
          "patternProperties" :{
            "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}":{
              "type":"object",
               "properties":{
                 "quantity":{
                   "type":"object",
                   "properties":{
                     "value":{
                       "type":"integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Viewes in JSONBuddy

over 4 years ago · Santiago Trujillo Report

0

Building on @pxcv7r's answer:

To validate UUID in particular, you may use format in JSON schema, which provides built-in support for the UUID syntax: { "type": "string", "format": "uuid" }

See https://json-schema.org/understanding-json-schema/reference/string.html

Additionally, you can use a combination of "propertyNames" and "unevaluatedProperties" to avoid the need for any regular expression:

{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "type": "object",
  "properties": {
    "status": {
      "type": "integer"
    },
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "shop": {
      "type": "object",
      "minProperties": 1,
      "maxProperties": 1,
      "propertyNames": {
        "format": "uuid"
      },
      "unevaluatedProperties": {
        "type":"object",
        "minProperties": 1,
        "propertyNames": {
          "format": "uuid"
        },
        "unevaluatedProperties": {
          "title": "single variant of a shop",
          "type": "object",
          "properties": {
            "quantity": {
              "type": "object",
              "properties": {
                "value": {
                  "type": "integer"
                }
              }
            }
          }
        }
      }
    }
  }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!