Crate formatjson5

source ·
Expand description

A command line interface (CLI) tool to format JSON5 (“JSON for Humans”) documents to a consistent style, preserving comments.

See json5format for more details.


formatjson5 [FLAGS] [OPTIONS] [files]...

-h, --help                  Prints help information
-n, --no_trailing_commas    Suppress trailing commas (otherwise added by default)
-o, --one_element_lines     Objects or arrays with a single child should collapse to a
                            single line; no trailing comma
-r, --replace               Replace (overwrite) the input file with the formatted result
-s, --sort_arrays           Sort arrays of primitive values (string, number, boolean, or
                            null) lexicographically
-V, --version               Prints version information

-i, --indent <indent>    Indent by the given number of spaces [default: 4]

<files>...    Files to format (use "-" for stdin)


Opt 🔒
Command line options defined via the structopt! macrorule. These definitions generate the option parsing, validation, and usage documentation.


Formats the given parsed documents, applying the given format options. If replace is true, each input file is overwritten by its formatted version.
main 🔒
The entry point for the formatjson5 command line interface.
Parses each file in the given files vector and returns a parsed object for each JSON5 document. If the parser encounters an error in any input file, the command aborts without formatting any of the documents.