Convert Figma logo to code with AI

json-schema-org logojson-schema-spec

The JSON Schema specification

3,620
257
3,620
85

Top Related Projects

The OpenAPI Specification Repository

API Blueprint

RAML Specification

4,188

The AsyncAPI specification allows you to create machine-readable definitions of your asynchronous APIs.

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API

Quick Overview

The json-schema-org/json-schema-spec repository contains the official specification for JSON Schema. JSON Schema is a vocabulary that allows you to annotate and validate JSON documents. This repository serves as the central location for the development and maintenance of the JSON Schema specification.

Pros

  • Provides a standardized way to describe JSON data structures
  • Enables automatic validation of JSON data against a schema
  • Supports documentation and code generation based on schemas
  • Widely adopted and supported by various tools and libraries

Cons

  • Can be complex for newcomers to understand and implement
  • Versioning and compatibility issues between different JSON Schema versions
  • Limited support for certain advanced data validation scenarios
  • May introduce overhead in terms of schema creation and maintenance

Code Examples

This repository is not a code library but a specification. Therefore, code examples are not applicable in this context. However, here are some examples of how JSON Schema might be used in practice:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer", "minimum": 0 }
  },
  "required": ["name"]
}

This example shows a simple JSON Schema that defines an object with a required "name" property (string) and an optional "age" property (non-negative integer).

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "id": { "type": "string", "format": "uuid" },
      "created_at": { "type": "string", "format": "date-time" }
    },
    "required": ["id", "created_at"]
  }
}

This example demonstrates a schema for an array of objects, where each object must have an "id" (UUID format) and a "created_at" (date-time format) property.

Getting Started

As this is a specification repository, there's no code to run directly. However, to get started with JSON Schema:

  1. Familiarize yourself with the specification at https://json-schema.org/
  2. Choose a JSON Schema validator library for your programming language
  3. Write your first schema and validate JSON data against it
  4. Explore more advanced features like references, combinators, and conditional schemas

For implementation details, refer to the documentation of the JSON Schema library you choose for your specific programming language or environment.

Competitor Comparisons

The OpenAPI Specification Repository

Pros of OpenAPI-Specification

  • More comprehensive API description, including endpoints, operations, and parameters
  • Built-in support for API documentation and client/server code generation
  • Wider adoption in the API development ecosystem

Cons of OpenAPI-Specification

  • More complex and verbose specification format
  • Less flexible for describing general-purpose data structures
  • Steeper learning curve for developers new to API design

Code Comparison

JSON Schema:

{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer", "minimum": 0 }
  }
}

OpenAPI Specification:

components:
  schemas:
    Person:
      type: object
      properties:
        name:
          type: string
        age:
          type: integer
          minimum: 0

Summary

JSON Schema is simpler and more focused on data validation, while OpenAPI Specification provides a more comprehensive approach to API design and documentation. JSON Schema is better suited for general-purpose data structure validation, while OpenAPI Specification excels in describing complete API ecosystems, including endpoints, operations, and documentation.

API Blueprint

Pros of API Blueprint

  • More human-readable format using Markdown syntax
  • Focuses on API documentation and design, including examples and use cases
  • Supports API mock creation and testing tools

Cons of API Blueprint

  • Less widely adopted compared to JSON Schema
  • Limited to API description, not as versatile for general data validation
  • Fewer tools and libraries available for parsing and validation

Code Comparison

API Blueprint:

# GET /users/{id}
+ Response 200 (application/json)
    {
        "id": 1,
        "name": "John Doe"
    }

JSON Schema:

{
  "type": "object",
  "properties": {
    "id": { "type": "integer" },
    "name": { "type": "string" }
  },
  "required": ["id", "name"]
}

API Blueprint uses a Markdown-based syntax to describe API endpoints and responses, making it more readable for humans. JSON Schema, on the other hand, uses a JSON-based format to define data structures and validation rules, which is more versatile for general data validation but less focused on API documentation.

While API Blueprint excels in API design and documentation, JSON Schema is better suited for data validation across various applications. The choice between the two depends on the specific needs of the project, with API Blueprint being more appropriate for API-centric development and JSON Schema for broader data structure definition and validation.

RAML Specification

Pros of RAML Spec

  • More human-readable syntax using YAML
  • Built-in support for describing API resources and methods
  • Includes features for API documentation and testing

Cons of RAML Spec

  • Less widely adopted compared to JSON Schema
  • Limited to API specifications, while JSON Schema is more versatile
  • Steeper learning curve for developers unfamiliar with YAML

Code Comparison

RAML Spec example:

#%RAML 1.0
title: Example API
/users:
  get:
    responses:
      200:
        body:
          application/json:
            type: array
            items:
              type: object
              properties:
                id: number
                name: string

JSON Schema Spec example:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "id": { "type": "number" },
      "name": { "type": "string" }
    },
    "required": ["id", "name"]
  }
}

The RAML Spec focuses on API structure and endpoints, while JSON Schema Spec concentrates on data validation and structure. RAML provides a more comprehensive API description, including methods and responses, whereas JSON Schema offers a more flexible approach to defining data schemas for various use cases beyond API specifications.

4,188

The AsyncAPI specification allows you to create machine-readable definitions of your asynchronous APIs.

Pros of AsyncAPI spec

  • Specifically designed for asynchronous APIs and event-driven architectures
  • Includes protocol-specific details for messaging systems (e.g., AMQP, MQTT)
  • Supports both publish and subscribe operations

Cons of AsyncAPI spec

  • Less widely adopted compared to JSON Schema
  • More complex structure due to additional messaging-specific elements
  • Limited tooling ecosystem compared to JSON Schema

Code comparison

AsyncAPI spec example:

asyncapi: 2.0.0
channels:
  user/signedup:
    publish:
      message:
        payload:
          type: object
          properties:
            userId:
              type: string
            signupDate:
              type: string
              format: date-time

JSON Schema spec example:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "userId": { "type": "string" },
    "signupDate": { "type": "string", "format": "date-time" }
  }
}

The AsyncAPI spec focuses on defining message structures and channels for asynchronous communication, while JSON Schema spec primarily describes data structures without specific messaging context. AsyncAPI incorporates elements from JSON Schema for payload definitions but extends it with messaging-specific concepts.

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)

Pros of openapi-generator

  • Generates client libraries, server stubs, and documentation for multiple programming languages
  • Supports a wide range of frameworks and platforms
  • Actively maintained with frequent updates and community contributions

Cons of openapi-generator

  • More complex setup and configuration compared to JSON Schema
  • May generate unnecessary code for simpler API specifications
  • Steeper learning curve for beginners

Code comparison

json-schema-spec:

{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer", "minimum": 0 }
  },
  "required": ["name"]
}

openapi-generator:

openapi: 3.0.0
info:
  title: User API
  version: 1.0.0
paths:
  /user:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                age:
                  type: integer
                  minimum: 0
              required:
                - name
      responses:
        '201':
          description: Created

The json-schema-spec focuses on defining data structures, while openapi-generator provides a more comprehensive API specification, including endpoints, request/response details, and additional metadata. openapi-generator is better suited for complete API documentation and code generation, while json-schema-spec is more lightweight and focused on data validation.

Examples and server integrations for generating the Swagger API Specification, which enables easy access to your REST API

Pros of swagger-core

  • More comprehensive API development toolset, including code generation and documentation
  • Better integration with Java ecosystem and Spring framework
  • Wider adoption in enterprise environments

Cons of swagger-core

  • More complex and opinionated compared to the simpler JSON Schema
  • Steeper learning curve for developers new to the OpenAPI ecosystem
  • Less flexibility for non-REST API use cases

Code comparison

json-schema-spec:

{
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer", "minimum": 0 }
  },
  "required": ["name"]
}

swagger-core:

openapi: 3.0.0
info:
  title: User API
  version: 1.0.0
paths:
  /users:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name: { type: string }
                age: { type: integer, minimum: 0 }
              required: [name]

The json-schema-spec focuses solely on data structure definition, while swagger-core provides a more comprehensive API description, including endpoints and operations. JSON Schema is more versatile for general data validation, whereas Swagger (OpenAPI) is tailored specifically for RESTful API documentation and development.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Welcome to JSON Schema

Contributor Covenant Project Status: Active – The project has reached a stable, usable state and is being actively developed. Financial Contributors on Open Collective

JSON Schema is a vocabulary that allows you to validate, annotate, and manipulate JSON documents.

This repository contains the sources for the work in progress of the next set of JSON Schema IETF Internet Draft (I-D) documents. For the latest released I-Ds, please see the Specification page on the website.

Call for contributions and feedback

Reviews, comments and suggestions are most welcome! Please read our guidelines for contributing.

Status

For the current status of issues and pull requests, please see the following labels

Available In Progress Review Needed

Critical High Medium Low

Labels are assigned based on Sensible Github Labels.

Authoring and Building

Specification

To build the spec files to HTML from the Markdown sources, run npm run build-all. You can also build each individually with npm run build -- filename.md (Example: npm run build -- jsonschema-core.md). You can also use wildcards to build multiple specs at the same time: npm run build -- jsonschema-*.md.

The spec is built using Remark, a markdown engine with good support for plugins and lots of existing plugins we can use.

Plugins

The following is a not-necessarily-complete list of configured plugins and the features they make available to you.

  • remark-lint -- Enforce markdown styles guide.

  • remark-validate-links -- Check for broken links.

  • remark-gfm -- Adds support for Github Flavored Markdown specific markdown features such as autolink literals, footnotes, strikethrough, tables, and tasklists.

  • remark-heading-id -- Adds support for {#my-anchor} syntax to add an id to an element so it can be referenced using URI fragment syntax.

  • remark-headings -- A collection of enhancements for headings.

    • Adds hierarchical section numbers to headings.
      • Use the [Appendix] prefix on headings that should be numbered as an appendix.
    • Adds id anchors to headers that don't have one
      • Example: #section-2-13
      • Example: #appendix-a
    • Makes the heading a link utilizing its anchor
  • remark-reference-links -- Adds new syntax for referencing a section of the spec using the section number as the link text.

    • Example:
    ## Foo {#foo}
    
    ## Bar
    This is covered in {{foo}} // --> Renders to "This is covered in [Section 2.3](#foo)"
    - Link text will use "Section" or "Appendix" as needed
    
  • remark-table-of-contents -- Adds a table of contents in a section with a header called "Table of Contents".

  • remark-code-titles -- Add titles to code blocks

    • Example:
      \`\`\`jsonschema "My Fun Title"
      { "type": "string" }
      \`\`\`
      
    • The languages jsonschema and json have special styling
    • The title will be parsed as a JSON string, but you have to double escape escaped characters. So, to get My "quoted" title, you would need to be "My \\\\"quoted\\\\" title".
  • remark-torchlight -- Syntax highlighting and more using https://torchlight.dev. Features include line numbers and line highlighting.

  • remark-flexible-containers -- Add a callout box using the following syntax. Supported container types are warning, note, and experimental.

    ::: {type} {title}
    {content}
    :::
    

Internet-Drafts

To build components that are being maintained as IETF Internet-Drafts, run make. The Makefile will create the necessary Python venv for you as part of the regular make target.

make clean will remove all output including the venv. To clean just the spec output and keep the venv, use make spec-clean.

If you want to run xml2rfc manually after running make for the first time, you will need to activate the virtual environment: source .venv/bin/activate.

The version of "xml2rfc" that this project uses is updated by modifying requirements.in and running pip-compile requirements.in.

Descriptions of the xml2rfc, I-D documents, and RFC processes:

Test suites

Conformance tests for JSON Schema and its vocabularies may be found in their own repository.

The website

The JSON Schema web site is at http://json-schema.org/

The source for the website is maintained in a separate repository.

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Sponsors

Here are our top sponsors. You could be next! [Become a sponsor]

Individuals

License

The contents of this repository are licensed under either the BSD 3-clause license or the Academic Free License v3.0.