Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

597
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda