Add JSON schema for JSON-LD documents
authorMads Kristensen <post@madskristensen.net>
Tue, 18 Mar 2014 10:10:24 +0100
changeset 2140 d858e1cf2ad7
parent 2139 f01d5c61a43b
child 2141 4ba4dfd6dfcc
Add JSON schema for JSON-LD documents

Squashed commit of the following:

commit c915635e3563bca6cae98c941784cac4259814c6
Merge: fe71c94 e16b086
Author: Markus Lanthaler <mark_lanthaler@gmx.net>
Date: Tue Mar 18 10:09:27 2014 +0100

Merge branch 'master' of https://github.com/madskristensen/json-ld.org into PR334

commit e16b08696050fcbc778af6224b700c732bb9e81c
Author: Mads Kristensen <post@madskristensen.net>
Date: Mon Mar 17 18:29:23 2014 -0700

Created /schema/ and moved the file there

commit 457f72580f9cb10bf0ac8df1a540043389c919e5
Author: Mads Kristensen <post@madskristensen.net>
Date: Mon Mar 17 06:50:07 2014 -0700

Fixed based on code review

I also removed the "id" property since it doesn't resolve.

commit 764d6c70473b97cf8c694b266f3c6cb0c511f22e
Author: Mads Kristensen <post@madskristensen.net>
Date: Sun Mar 16 09:40:33 2014 -0700

Minor fix and formatting tweaks

commit 1e4a76a13765f8bb4e99e730b5c89987123c591f
Author: Mads Kristensen <post@madskristensen.net>
Date: Sun Mar 16 09:05:21 2014 -0700

JSON schema for JSON-LD documents

This will allow JSON editors to provide statement completion and
tooltips for authors of JSON-LD documents.

I validated all the examples of JSON-LD I could find using
http://json-schema-validator.herokuapp.com/

This closes #334
schemas/jsonld-schema.json
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schemas/jsonld-schema.json	Tue Mar 18 10:10:24 2014 +0100
@@ -0,0 +1,90 @@
+{
+    "title": "Schema for JSON-LD",
+    "$schema": "http://json-schema.org/draft-04/schema#",
+    
+    "definitions":{
+        "context": {
+            "additionalProperties": true,
+            "properties": {
+                "@context": {
+                    "description": "Used to define the short-hand names that are used throughout a JSON-LD document.",
+                    "type": ["object", "string", "array", "null"]
+                }
+            }
+        },
+        "graph": {
+            "additionalProperties": true,
+            "properties": {
+                "@graph": {
+                    "description": "Used to express a graph.",
+                    "type": ["array", "object"],
+                    "additionalItems": {
+                        "anyOf": [{ "$ref": "#/definitions/common" }]
+                    }
+                }
+            }
+        },
+        "common":{
+            "additionalProperties": {
+                "anyOf": [{ "$ref": "#/definitions/common" }]
+            },
+            "properties": {
+                "@id": {
+                    "description": "Used to uniquely identify things that are being described in the document with IRIs or blank node identifiers.",
+                    "type": "string",
+                    "format": "uri"
+                },
+                "@value": {
+                    "description": "Used to specify the data that is associated with a particular property in the graph.",
+                    "type": ["string", "boolean", "number", "null"]
+                },
+                "@language": {
+                    "description": "Used to specify the language for a particular string value or the default language of a JSON-LD document.",
+                    "type": ["string", "null"]
+                },
+                "@type": {
+                    "description": "Used to set the data type of a node or typed value.",
+                    "type": ["string", "null"],
+                    "enum": ["@id"]
+                },
+                "@container": {
+                    "description": "Used to set the default container type for a term.",
+                    "type": ["string", "null"],
+                    "enum": ["@list", "@index", "@set"]
+                },
+                "@list": {
+                    "description": "Used to express an ordered set of data."
+                },
+                "@set": {
+                    "description": "Used to express an unordered set of data and to ensure that values are always represented as arrays."
+                },
+                "@reverse": {
+                    "description": "Used to express reverse properties.",
+                    "type": ["string", "object", "null"],
+                    "additionalProperties": {
+                        "anyOf": [{ "$ref": "#/definitions/common" }]
+                    }
+                },
+                "@base": {
+                    "description": "Used to set the base IRI against which relative IRIs are resolved",
+                    "type": ["string", "null"],
+                    "format": "uri"
+                },
+                "@vocab": {
+                    "description": "Used to expand properties and values in @type with a common prefix IRI",
+                    "type": ["string", "null"],
+                    "format": "uri"
+                }
+            }
+        }
+    },
+
+    "anyOf": [
+        { "$ref": "#/definitions/context" },
+        { "$ref": "#/definitions/graph" },
+        { "$ref": "#/definitions/common" }
+    ],
+
+    "type": ["object", "array"],
+    "additionalProperties": true
+}
\ No newline at end of file