Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

602
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda