# Compilation into JSON-LD Context

Our fictitious application uses [JSON-LD](https://json-ld.org/) to communicate messages between the different blogging servers constituting of the federation. JSON-LD is a JSON-based data exchange format. Whereas JSON Schema imposes constraints on the structure of the JSON document, JSON-LD does not impose any structural constraint. In return, JSON-LD requires the document to contain a **JSON-LD context** specifying the semantics of each part of the document. This means that two radically different JSON-LD documents can represent the exact same data thanks to their context definition.

Assume that we want to represent a `BlogPost` instance using the following JSON-LD document:

```json
{
	"@context": ...,
	"title": "The Blog Post Title",
	"content": "The blog post content."
}
```

The `@context` key has a special meaning in JSON-LD and should contain the JSON-LD context necessary to interpret the document. In particular, it should specify how to interpret the `title` and `content` keys. In our case, those refer to the `https://example.com/BlogPost/title` and `https://example.com/BlogPost/content` properties respectively. We can hence define the JSON-LD context as so:

```json
{
	"title": "https://example.com/BlogPost/title",
	"content": "https://example.com/BlogPost/content"
}
```

Once again instead of defining the JSON-LD context by hand, TreeLDR can generate it automatically using the `tldrc` compiler and the following command:

```
tldrc -i schema.tldr json-ld-context https://example.com/BlogPost
```

It is very similar to the command used to generate a JSON Schema. It imports the `schema.tldr` with the `-i` option, calls the `json-ld-context` subcommand to generate a JSON-LD context and specifies what context we want to generate. Here we want to generate a JSON-LD context for `BlogPost`, which is identified by the `https://example.com/BlogPost` IRI.&#x20;

The output should match the JSON-LD context above.
