JSON Include Directives¶
Standard JSON Include¶
- .. jsoninclude::¶
Include a section of a JSON file, given a jsonpointer.
e.g. using this json file:
Source:
```{eval-rst} .. jsoninclude:: _static/example.json :jsonpointer: /a/0/b :expand: e ```Output:
The
expandoption is needed to expand a list when the json is folded by javascript. For more info see Javascript below.excludeoption:Source:
```{eval-rst} .. jsoninclude:: _static/example.json :jsonpointer: /a/0/b :exclude: e,g ```Output:
include_onlyoption:Source:
```{eval-rst} .. jsoninclude:: _static/example.json :jsonpointer: /a/0/b :include_only: e,g :expand: e ```Output:
Javascript¶
To fold the JSON with javascript, you need to include the following files:
You need to add the files to a _static folder within your docs, and then add the following to _templates/layout.html.
{% extends "!layout.html" %}
{% set css_files = css_files + ["_static/renderjson.css"] %}
{% set script_files = script_files + ["_static/renderjson.js", "_static/json-example-format.js"] %}
The option expand can be used to control which lists are expanded initially. The option title can be used to give the json include a title; only one of consecutive includes will be shown, with a select box to switch:
Source:
```{eval-rst}
.. jsoninclude:: _static/example.json
:jsonpointer:
:title: collapsed
.. jsoninclude:: _static/example.json
:jsonpointer:
:expand: a,b,e,h
:title: expanded
```
Output:
Flat JSON Include¶
- .. jsoninclude-flat::¶
Include a section of a JSON file, flattened into a table representation, given a jsonpointer.
Examples, using this json file:
Source:
```{eval-rst} .. jsoninclude-flat:: _static/example.json :jsonpointer: /a/0/b ```Output:
/a/0/b/c
/a/0/b/d
/a/0/b/g
1
2
5
recursive(include nested dicts and lists):Source:
```{eval-rst} .. jsoninclude-flat:: _static/example.json :jsonpointer: /a/0/b :recursive: ```Output:
/a/0/b/c
/a/0/b/d
/a/0/b/e/0/f
/a/0/b/e/1/f
/a/0/b/g
1
2
3
4
5
List of items directly under the json pointer:
Source:
```{eval-rst} .. jsoninclude-flat:: _static/example.json :jsonpointer: /h ```Output:
/h/k
/h/l
11
12
13
14
Remove part of the path from the headings uwsing
ignore_path:Source:
```{eval-rst} .. jsoninclude-flat:: _static/example.json :jsonpointer: /a/0/b :ignore_path: /a/0/b/ ```Output:
c
d
g
1
2
5
jsoninclude-flatalso has the optionsexcludeandinclude_only, the same as forjsoninclude(see above).
JSON Include Quoted¶
- .. jsoninclude-quote::¶
Include a value from a JSON file, inside a blockquote, given a jsonpointer.
e.g. using this json file:
Source:
```{eval-rst} .. jsoninclude-quote:: _static/example_schema.json :jsonpointer: /properties/lorem/description ```Output:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur porttitor urna in diam ornare luctus. Donec accumsan sit amet velit id auctor. Sed commodo elit ut tempor suscipit. Fusce volutpat malesuada felis, accumsan molestie nisi aliquet non. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Some markdown.