JSON v2: Difference between revisions

From John's wiki
Jump to navigation Jump to search
(work, work...)
(work, work...)
Line 1: Line 1:
These are some thoughts on an improved JSON data-format that includes support for namespaces and schema description.
These are some thoughts on an improved JSON data-format that includes support for namespaces and schema description.


We also want to optionally include a [http://json-schema.org/ JSON schema] for a namespace. Schema could be either inline or a URL which would return the schema.
We want to optionally include a [http://json-schema.org/ JSON schema] for a namespace. Schema could be either inline or a URL which would return the schema. For example below the 'jj5' schema is inline but the 'example' schema is by-ref.
 
The rules for namespaces are that you have to nominate an alias for each namespace that you use. The alias 'default' is special (a reserved word) and it is used to point to the alias for the namespace which is assumed when no namespace alias appears on data items.


  var data = {
  var data = {
Line 7: Line 9:
     "version": 2,
     "version": 2,
     "namespace": {
     "namespace": {
       "default": "net.jj5.json.schema.example.v2",
       "default": "jj5",
      "jj5": "net.jj5.json.schema.example.v2",
       "ex": "com.example.json.schema.example.v1"
       "ex": "com.example.json.schema.example.v1"
     },
     },
Line 18: Line 21:
         }
         }
       ]
       ]
    },
    "schema": {
      "jj5": {
        "title": "Person",
        "type": "object",
        "properties": {
            "first_name": {
              "type": "string"
            },
            "last_name": {
              "type": "string"
            },
            "age": {
              "description": "Age in years",
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "required": [ "first_name", "last_name" ]
      },
      "example": "https://v1.example.schema.json.example.com/schema.json"
     }
     }
   }
   }
  };
  };

Revision as of 13:03, 8 July 2017

These are some thoughts on an improved JSON data-format that includes support for namespaces and schema description.

We want to optionally include a JSON schema for a namespace. Schema could be either inline or a URL which would return the schema. For example below the 'jj5' schema is inline but the 'example' schema is by-ref.

The rules for namespaces are that you have to nominate an alias for each namespace that you use. The alias 'default' is special (a reserved word) and it is used to point to the alias for the namespace which is assumed when no namespace alias appears on data items.

var data = {
  "json": {
    "version": 2,
    "namespace": {
      "default": "jj5",
      "jj5": "net.jj5.json.schema.example.v2",
      "ex": "com.example.json.schema.example.v1"
    },
    "data": {
      "people": [
        {
          "first_name": "John",
          "last_name": "Elliot",
          "ex:lucky_number": 37
        }
      ]
    },
    "schema": {
      "jj5": {
       "title": "Person",
        "type": "object",
        "properties": {
           "first_name": {
              "type": "string"
            },
            "last_name": {
              "type": "string"
            },
            "age": {
              "description": "Age in years",
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "required": [ "first_name", "last_name" ]
      },
      "example": "https://v1.example.schema.json.example.com/schema.json"
    }
  }
};