jsonyx format¶
Re-format or validate a JSON file.
Usage¶
jsonyx format [-h] [-a] [-c] [-C] [-d] [-i SPACES] [-l] [-L LEVEL] [-s]
[-S] [-t] [-T] [-q] [input_filename] [output_filename]
Positional arguments¶
- input_filename¶
The path to the input JSON file, or
"-"for standard input. If not specified, read fromsys.stdin.
- output_filename¶
The path to the output JSON file. If not specified, write to
sys.stdout.
Options¶
- -h, --help¶
Show the help message and exit.
- -a, --ensure-ascii¶
Escape non-ASCII characters.
- -c, --compact¶
Avoid unnecessary whitespace after
","and":".
- -C, --no-commas¶
Don’t separate items by commas when indented.
- -d, --use-decimal¶
Use
decimal.Decimalinstead offloat.
- -i, --indent SPACES¶
Indent using the specified number of spaces.
- -l, --no-indent-leaves¶
Don’t indent leaf objects and arrays.
- -L, --max-indent-level¶
The level up to which to indent.
- -q, --unquoted-keys¶
Don’t quote keys which are identifiers.
- -s, --sort-keys¶
Sort the keys of objects.
- -t, --trailing-comma¶
Add a trailing comma when indented.
- -T, --indent-tab¶
Indent using tabs.
Example¶
$ echo '{"foo": [1, 2, 3], "bar": {"a": 1, "b": 2, "c": 3}}' | jsonyx format \
--indent 4 \
--no-indent-leaves
{
"foo": [1, 2, 3],
"bar": {"a": 1, "b": 2, "c": 3}
}
$ echo "{1.2: 3.4}" | jsonyx format
File "<stdin>", line 1, column 2
{1.2: 3.4}
^
jsonyx.JSONSyntaxError: Expecting string