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
expand
option is needed to expand a list when the json is folded by javascript. For more info see Javascript below.exclude
option:Source:
```{eval-rst} .. jsoninclude:: _static/example.json :jsonpointer: /a/0/b :exclude: e,g ```
Output:
include_only
option: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-flat
also has the optionsexclude
andinclude_only
, the same as forjsoninclude
(see above).