liveBook · Manning

JSON Pointer

As explained in The Design of Web APIs, Second Edition

JSON Pointer is a standardized string syntax for identifying a specific value within a JSON document.

JSON Pointer is a standardized string syntax for identifying a value within a JSON or YAML document. In OpenAPI, a pointer lets $ref locate reusable schemas and other components instead of duplicating their definitions. section 7.7.1

A pointer begins at the document root, marked by #, and follows slash-separated property names. Thus #/components/schemas/Product identifies the Product schema under components.schemas. Reusing that target keeps request and response models consistent and limits future changes to one definition. section 7.7.1 section 7.8

Listing 7.12 References to reusable schemas
...
paths:
  /products:
    ...
    post:
      ...
      responses:
        "201":
          ...
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Product"    #1

  ...
  /products/{productReference}:
    get:
     ...
      responses:
        "200":
          ...
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Product"   #1

...
components:
  schemas:
    Product: ...    #1

Use the same pointer to return the Product schema from both product-creation and product-retrieval responses. section 7.7.1

JSON Pointer also supports practical API tooling and error-reporting tasks:

  • Target reusable error schemas, parameters, request bodies, headers, and responses from their component locations. section 17.8
  • Identify the precise request-body location of a validation problem so consumers can display actionable feedback in a user interface. section 9.8.4
  • Point Spectral overrides at individual lint findings; encode path slashes as ~1, as in #/paths/~1accounts/get/parameters. section 18.9.2

How The Design of Web APIs, Second Edition covers it

How deep it goes
Explains root markers, slash-separated properties, reuse, and slash escaping, but does not develop the full standard grammar.
Examples
Demonstrates Product schema references, request-body error locations, and a Spectral override for an accounts endpoint.
What it assumes
Assumes familiarity with JSON or YAML documents, OpenAPI components, JSON Schema, and API request and response structures.
What you can do after
Apply JSON Pointer to configure reusable OpenAPI references, locate API errors, and suppress selected Spectral findings.
How it connects
Connects JSON Pointer with JSON Schema, OpenAPI, $ref, reusable components, machine-readable errors, and Spectral.

Also explained in

Compare how 2 books explain JSON Pointer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Design of Web APIs, Second Edition. The section links point to the parts of the book it draws on.