Compilation into JSON Schema

Our fictitious application uses JSON to communicate messages between the blogging server and the client that displays blog posts. Each exchanged JSON document contains information about users or blog posts. Information must be organized in a certain way agreed upon by the client and server. This can be formalized using a JSON Schema specifying the structure of the exchanged JSON documents. For instance, here is a possible JSON Schema describing the structure of a JSON document containing a blog post (it is also a JSON document):

	"type": "object",
	"properties": {
		"title": {
			"type": "string"
		"content": {
			"type": "string"
	"required": [

You may notice that this definition is very close to the TreeLDR definition of BlogPost. For this reason, TreeLDR can be used to automatically generate this schema from our schema.tldr file using the tldrc compiler.

On linux or macOS, type the following command in your terminal:

tldrc -i schema.tldr json-schema

This commands imports the schema.tldr with the -i option, calls the json-schema subcommand to generate a JSON Schema and specifies what schema we want to generate. Here we want to generate a JSON Schema for BlogPost, which is identified by the IRI (once resolved against the base IRI). The output should match the JSON Schema above.

Last updated