Cara menggunakan python-jsonschema-objects

Partial support for and , except for dynamicRef / recursiveRef and $vocabulary (in-progress). Full support for , , and

  • that can iteratively report all validation errors.

  • Programmatic querying of which properties or items failed validation.

  • Installation

    jsonschema is available on PyPI. You can install using pip:

    $ pip install jsonschema
    

    Extras

    Two extras are available when installing the package, both currently related to

    $ jsonschema --instance sample.json sample.schema
    
    0 validation:

    • $ jsonschema --instance sample.json sample.schema
      
      0

    • $ jsonschema --instance sample.json sample.schema
      
      2

    They can be used when installing in order to include additional dependencies, e.g.:

    $ pip install jsonschema'[format]'
    

    Be aware that the mere presence of these dependencies – or even the specification of

    $ jsonschema --instance sample.json sample.schema
    
    0 checks in a schema – do not activate format checks (as per the specification). Please read the for further details.

    Running the Test Suite

    If you have

    $ jsonschema --instance sample.json sample.schema
    
    4 installed (perhaps via
    $ jsonschema --instance sample.json sample.schema
    
    5 or your package manager), running
    $ jsonschema --instance sample.json sample.schema
    
    4 in the directory of your source checkout will run jsonschema’s test suite on all of the versions of Python jsonschema supports. If you don’t have all of the versions that jsonschema is tested under, you’ll likely want to run using
    $ jsonschema --instance sample.json sample.schema
    
    4’s
    $ pip install jsonschema
    
    1 option.

    Of course you’re also free to just run the tests on a single version with your favorite test runner. The tests live in the

    $ pip install jsonschema
    
    2 package.

    Benchmarks

    jsonschema’s benchmarks make use of pyperf. Running them can be done via:

    $ tox -e perf
    

    Community

    The JSON Schema specification has a Slack, with an invite link on its home page. Many folks knowledgeable on authoring schemas can be found there.

    Otherwise, asking questions on Stack Overflow is another means of getting help if you’re stuck.

    About

    I’m Julian Berman.

    jsonschema is on GitHub.

    Get in touch, via GitHub or otherwise, if you’ve got something to contribute, it’d be most welcome!

    You can also generally find me on Libera (nick:

    $ pip install jsonschema
    
    5) in various channels, including
    $ pip install jsonschema
    
    6.

    If you feel overwhelmingly grateful, you can also sponsor me.

    And for companies who appreciate jsonschema and its continued support and growth, jsonschema is also now supportable via TideLift.

    The following example is by no means definitive of all the value JSON Schema can provide. For this you will need to go deep into the specification itself – learn more at https://json-schema.org/specification.html.

    Let’s pretend we’re interacting with a JSON based product catalog. This catalog has a product which has:

    • An identifier:
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      0
    • A product name:
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      1
    • A selling cost for the consumer:
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      2
    • An optional set of tags:
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      3.

    For example:

    {
      "productId": 1,
      "productName": "A green door",
      "price": 12.50,
      "tags": [ "home", "green" ]
    }
    

    While generally straightforward, the example leaves some open questions. Here are just a few of them:

    • What is
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      0?
    • Is
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      1 required?
    • Can the
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      2 be zero (0)?
    • Are all of the
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      3 string values?

    When you’re talking about a data format, you want to have metadata about what keys mean, including the valid inputs for those keys. JSON Schema is a proposed IETF standard how to answer those questions for data.

    Starting the schema

    To start a schema definition, let’s begin with a basic JSON schema.

    We start with four properties called keywords which are expressed as JSON keys.

    Yes. the standard uses a JSON data document to describe data documents, most often that are also JSON data documents but could be in any number of other content types like

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://example.com/product.schema.json",
      "title": "Product",
      "description": "A product in the catalog",
      "type": "object"
    }
    
    8.

    • The keyword states that this schema is written according to a specific draft of the standard and used for a variety of reasons, primarily version control.
    • The keyword defines a URI for the schema, and the base URI that other URI references within the schema are resolved against.
    • The and annotation keywords are descriptive only. They do not add constraints to the data being validated. The intent of the schema is stated with these two keywords.
    • The validation keyword defines the first constraint on our JSON data and in this case it has to be a JSON Object.

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://example.com/product.schema.json",
      "title": "Product",
      "description": "A product in the catalog",
      "type": "object"
    }
    

    We introduce the following pieces of terminology when we start the schema:

    • :
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      9 and
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          }
        },
        "required": [ "productId" ]
      }
      
      0.
    • :
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          }
        },
        "required": [ "productId" ]
      }
      
      1 and
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          }
        },
        "required": [ "productId" ]
      }
      
      2.
    • :
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          }
        },
        "required": [ "productId" ]
      }
      
      3.

    Defining the properties

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://example.com/product.schema.json",
      "title": "Product",
      "description": "A product in the catalog",
      "type": "object"
    }
    
    0 is a numeric value that uniquely identifies a product. Since this is the canonical identifier for a product, it doesn’t make sense to have a product without one, so it is required.

    In JSON Schema terms, we update our schema to add:

    • The validation keyword.
    • The
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      0 key.
      • {
          "$schema": "https://json-schema.org/draft/2020-12/schema",
          "$id": "https://example.com/product.schema.json",
          "title": "Product",
          "description": "A product from Acme's catalog",
          "type": "object",
          "properties": {
            "productId": {
              "description": "The unique identifier for a product",
              "type": "integer"
            }
          },
          "required": [ "productId" ]
        }
        
        2 schema annotation and
        {
          "$schema": "https://json-schema.org/draft/2020-12/schema",
          "$id": "https://example.com/product.schema.json",
          "title": "Product",
          "description": "A product from Acme's catalog",
          "type": "object",
          "properties": {
            "productId": {
              "description": "The unique identifier for a product",
              "type": "integer"
            }
          },
          "required": [ "productId" ]
        }
        
        3 validation keyword is noted – we covered both of these in the previous section.
    • The validation keyword listing
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      0.

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://example.com/product.schema.json",
      "title": "Product",
      "description": "A product from Acme's catalog",
      "type": "object",
      "properties": {
        "productId": {
          "description": "The unique identifier for a product",
          "type": "integer"
        }
      },
      "required": [ "productId" ]
    }
    

    • {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      1 is a string value that describes a product. Since there isn’t much to a product without a name it also is required.
    • Since the
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          },
          "productName": {
            "description": "Name of the product",
            "type": "string"
          }
        },
        "required": [ "productId", "productName" ]
      }
      
      4 validation keyword is an array of strings we can note multiple keys as required; We now include
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      1.
    • There isn’t really any difference between
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      0 and
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      1 – we include both for completeness since computers typically pay attention to identifiers and humans typically pay attention to names.

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://example.com/product.schema.json",
      "title": "Product",
      "description": "A product from Acme's catalog",
      "type": "object",
      "properties": {
        "productId": {
          "description": "The unique identifier for a product",
          "type": "integer"
        },
        "productName": {
          "description": "Name of the product",
          "type": "string"
        }
      },
      "required": [ "productId", "productName" ]
    }
    

    Going deeper with properties

    According to the store owner there are no free products. ;)

    • The
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      2 key is added with the usual
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          }
        },
        "required": [ "productId" ]
      }
      
      2 schema annotation and
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          }
        },
        "required": [ "productId" ]
      }
      
      3 validation keywords covered previously. It is also included in the array of keys defined by the
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          },
          "productName": {
            "description": "Name of the product",
            "type": "string"
          }
        },
        "required": [ "productId", "productName" ]
      }
      
      4 validation keyword.
    • We specify the value of
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      2 must be something other than zero using the validation keyword.
      • If we wanted to include zero as a valid price we would have specified the validation keyword.

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://example.com/product.schema.json",
      "title": "Product",
      "description": "A product from Acme's catalog",
      "type": "object",
      "properties": {
        "productId": {
          "description": "The unique identifier for a product",
          "type": "integer"
        },
        "productName": {
          "description": "Name of the product",
          "type": "string"
        },
        "price": {
          "description": "The price of the product",
          "type": "number",
          "exclusiveMinimum": 0
        }
      },
      "required": [ "productId", "productName", "price" ]
    }
    

    Next, we come to the

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://example.com/product.schema.json",
      "title": "Product",
      "description": "A product in the catalog",
      "type": "object"
    }
    
    3 key.

    The store owner has said this:

    • If there are tags there must be at least one tag,
    • All tags must be unique; no duplication within a single product.
    • All tags must be text.
    • Tags are nice but they aren’t required to be present.

    Therefore:

    • The
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product in the catalog",
        "type": "object"
      }
      
      3 key is added with the usual annotations and keywords.
    • This time the
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          }
        },
        "required": [ "productId" ]
      }
      
      3 validation keyword is
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          },
          "productName": {
            "description": "Name of the product",
            "type": "string"
          },
          "price": {
            "description": "The price of the product",
            "type": "number",
            "exclusiveMinimum": 0
          },
          "tags": {
            "description": "Tags for the product",
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "uniqueItems": true
          }
        },
        "required": [ "productId", "productName", "price" ]
      }
      
      1.
    • We introduce the validation keyword so we can define what appears in the array. In this case:
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          },
          "productName": {
            "description": "Name of the product",
            "type": "string"
          },
          "price": {
            "description": "The price of the product",
            "type": "number",
            "exclusiveMinimum": 0
          },
          "tags": {
            "description": "Tags for the product",
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "uniqueItems": true
          }
        },
        "required": [ "productId", "productName", "price" ]
      }
      
      3 values via the
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          }
        },
        "required": [ "productId" ]
      }
      
      3 validation keyword.
    • The validation keyword is used to make sure there is at least one item in the array.
    • The validation keyword notes all of the items in the array must be unique relative to one another.
    • We did not add this key to the
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          },
          "productName": {
            "description": "Name of the product",
            "type": "string"
          }
        },
        "required": [ "productId", "productName" ]
      }
      
      4 validation keyword array because it is optional.

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://example.com/product.schema.json",
      "title": "Product",
      "description": "A product from Acme's catalog",
      "type": "object",
      "properties": {
        "productId": {
          "description": "The unique identifier for a product",
          "type": "integer"
        },
        "productName": {
          "description": "Name of the product",
          "type": "string"
        },
        "price": {
          "description": "The price of the product",
          "type": "number",
          "exclusiveMinimum": 0
        },
        "tags": {
          "description": "Tags for the product",
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1,
          "uniqueItems": true
        }
      },
      "required": [ "productId", "productName", "price" ]
    }
    

    Nesting data structures

    Up until this point we’ve been dealing with a very flat schema – only one level. This section demonstrates nested data structures.

    • The
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          },
          "productName": {
            "description": "Name of the product",
            "type": "string"
          },
          "price": {
            "description": "The price of the product",
            "type": "number",
            "exclusiveMinimum": 0
          },
          "tags": {
            "description": "Tags for the product",
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "uniqueItems": true
          }
        },
        "required": [ "productId", "productName", "price" ]
      }
      
      8 key is added using the concepts we’ve previously discovered. Since the
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          }
        },
        "required": [ "productId" ]
      }
      
      3 validation keyword is
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          },
          "productName": {
            "description": "Name of the product",
            "type": "string"
          },
          "price": {
            "description": "The price of the product",
            "type": "number",
            "exclusiveMinimum": 0
          },
          "tags": {
            "description": "Tags for the product",
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "uniqueItems": true
          },
          "dimensions": {
            "type": "object",
            "properties": {
              "length": {
                "type": "number"
              },
              "width": {
                "type": "number"
              },
              "height": {
                "type": "number"
              }
            },
            "required": [ "length", "width", "height" ]
          }
        },
        "required": [ "productId", "productName", "price" ]
      }
      
      0 we can use the
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          },
          "productName": {
            "description": "Name of the product",
            "type": "string"
          }
        },
        "required": [ "productId", "productName" ]
      }
      
      0 validation keyword to define a nested data structure.
      • We omitted the
        {
          "$schema": "https://json-schema.org/draft/2020-12/schema",
          "$id": "https://example.com/product.schema.json",
          "title": "Product",
          "description": "A product from Acme's catalog",
          "type": "object",
          "properties": {
            "productId": {
              "description": "The unique identifier for a product",
              "type": "integer"
            }
          },
          "required": [ "productId" ]
        }
        
        2 annotation keyword for brevity in the example. While it’s usually preferable to annotate thoroughly in this case the structure and key names are fairly familiar to most developers.
    • You will note the scope of the
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          },
          "productName": {
            "description": "Name of the product",
            "type": "string"
          }
        },
        "required": [ "productId", "productName" ]
      }
      
      4 validation keyword is applicable to the dimensions key and not beyond.

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://example.com/product.schema.json",
      "title": "Product",
      "description": "A product from Acme's catalog",
      "type": "object",
      "properties": {
        "productId": {
          "description": "The unique identifier for a product",
          "type": "integer"
        },
        "productName": {
          "description": "Name of the product",
          "type": "string"
        },
        "price": {
          "description": "The price of the product",
          "type": "number",
          "exclusiveMinimum": 0
        },
        "tags": {
          "description": "Tags for the product",
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "dimensions": {
          "type": "object",
          "properties": {
            "length": {
              "type": "number"
            },
            "width": {
              "type": "number"
            },
            "height": {
              "type": "number"
            }
          },
          "required": [ "length", "width", "height" ]
        }
      },
      "required": [ "productId", "productName", "price" ]
    }
    

    References outside the schema

    So far our JSON schema has been wholly self contained. It is very common to share JSON schema across many data structures for reuse, readability and maintainability among other reasons.

    For this example we introduce a new JSON Schema resource and for both properties therein:

    • We use the
      {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "$id": "https://example.com/product.schema.json",
        "title": "Product",
        "description": "A product from Acme's catalog",
        "type": "object",
        "properties": {
          "productId": {
            "description": "The unique identifier for a product",
            "type": "integer"
          },
          "productName": {
            "description": "Name of the product",
            "type": "string"
          },
          "price": {
            "description": "The price of the product",
            "type": "number",
            "exclusiveMinimum": 0
          }
        },
        "required": [ "productId", "productName", "price" ]
      }
      
      7 validation keyword noted earlier.
    • We add the validation keyword.
    • Combined, these give us a range to use in validation.

    {
      "$id": "https://example.com/geographical-location.schema.json",
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "Longitude and Latitude",
      "description": "A geographical coordinate on a planet (most commonly Earth).",
      "required": [ "latitude", "longitude" ],
      "type": "object",
      "properties": {
        "latitude": {
          "type": "number",
          "minimum": -90,
          "maximum": 90
        },
        "longitude": {
          "type": "number",
          "minimum": -180,
          "maximum": 180
        }
      }
    }
    

    Next we add a reference to this new schema so it can be incorporated.

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "https://example.com/product.schema.json",
      "title": "Product",
      "description": "A product from Acme's catalog",
      "type": "object",
      "properties": {
        "productId": {
          "description": "The unique identifier for a product",
          "type": "integer"
        },
        "productName": {
          "description": "Name of the product",
          "type": "string"
        },
        "price": {
          "description": "The price of the product",
          "type": "number",
          "exclusiveMinimum": 0
        },
        "tags": {
          "description": "Tags for the product",
          "type": "array",
          "items": {
            "type": "string"
          },
          "minItems": 1,
          "uniqueItems": true
        },
        "dimensions": {
          "type": "object",
          "properties": {
            "length": {
              "type": "number"
            },
            "width": {
              "type": "number"
            },
            "height": {
              "type": "number"
            }
          },
          "required": [ "length", "width", "height" ]
        },
        "warehouseLocation": {
          "description": "Coordinates of the warehouse where the product is located.",
          "$ref": "https://example.com/geographical-location.schema.json"
        }
      },
      "required": [ "productId", "productName", "price" ]
    }
    

    Taking a look at data for our defined JSON Schema

    We’ve certainly expanded on the concept of a product since our earliest sample data (scroll up to the top). Let’s take a look at data which matches the JSON Schema we have defined.