Skip to content

Proposal: "jsonpointer" type #23

Open
@erosb

Description

@erosb

Introduction

While the JSON Schema specification itself utilizes JSON Pointers, it has only a very basic support for letting schema authors specify a schema which expects JSON documents to use such JSON Pointers. Currently, when a schema author wants to describe a JSON Pointer, the only thing he/she can do is defining the schema with "type":"string" and probably adding a regex restriction which mandates the string to be a syntactically valid json pointer.

In practical usecases it is useful to be able to describe the schema of the referred JSON value. This proposal targets these usecases.

Purpose

The purpose of this new type is to let schema authors expect that the document being validated contains a JSON Pointer, and this pointer denotes a value which conforms to the restrictions of a schema defined by the schema author.

Syntax

Example schema:

{
    "properties": {
        "ptrToNum": {
            "type": "jsonpointer",
            "referredSchema": {
                "type": "number"
            }
        }
    }
}

Example valid document against the above schema:

{
    "ptrToNum" : "#/settings/width",
    "settings" : {
        "width" : 4
    }
}

Example invalid document against the above schema:

{
    "ptrToNum" : "#/settings/width",
    "settings" : {
        "width" : [ 4 ]
    }
}

Validation

If a schema instance has a "type" : "jsonpointer" property , then it must also have a "referredSchema" key and a then an implementation should perform the following validation steps:

  • it should validate if the value is valid against the {"type" : "string"} schema
  • it should check if the string value is a valid JSON Pointer as specified by RFC 6901 (question: string representation or URI fragment identifier representation or both?)
  • it should evaluate the JSON Pointer. The result of the evaluation is a JSON value. If the evaluation fails then the validation is unsuccessful
  • it should validate the evaluated JSON value against the schema given by "referredSchema"

Notes

  • I'm not sure about the "referredSchema" keyword , maybe something more expressive can be better
  • while writing the above proposal I didn't take the wording of the current spec into account so probably most of it must be re-phrased. I'm also not sure if it should go into the core or the validation spec.
  • we should specify what should be done by the implementation if it runs into infinite recursion while resolving JSON pointers
  • so please take it as a draft / suggestion in its current form. If I get some positive feedback or some advices then I will create a proper pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions