#json5 #comments #formatter #style #json #command-line


Customizable JSON5 document formatter that preserves comments

11 releases

0.2.6 Jun 17, 2022
0.2.5 Jun 16, 2022
0.2.4 Jan 19, 2022
0.2.0 Mar 11, 2021
0.1.1 Apr 27, 2020

#491 in Encoding

Download history 46/week @ 2024-02-26 56/week @ 2024-03-04 83/week @ 2024-03-11 18/week @ 2024-03-18 24/week @ 2024-03-25 44/week @ 2024-04-01 23/week @ 2024-04-08 99/week @ 2024-04-15 116/week @ 2024-04-22 65/week @ 2024-04-29 54/week @ 2024-05-06 32/week @ 2024-05-13 48/week @ 2024-05-20 31/week @ 2024-05-27 16/week @ 2024-06-03 24/week @ 2024-06-10

120 downloads per month
Used in jsonpretty5er




json5format is a general purpose Rust library that formats JSON5 (a.k.a., "JSON for Humans"), preserving contextual line and block comments.

crates.io license docs.rs json5format

json5format Rust library

The json5format library includes APIs to customize the document format, with style options configurable both globally (affecting the entire document) as well as tailoring specific subsets of a target JSON5 schema. (See the Rust package documentation for more details and examples.) As of version 0.2.0, public APIs allow limited support for accessing the information inside a parsed document, and for injecting or modifying comments.

formatjson5 command line tool

The json5format package also bundles an example command line tool, formatjson5, that formats JSON5 documents using a basic style with some customizations available through command line options:

$ cargo build --example formatjson5
$ ./target/debug/examples/formatjson5 --help

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)

NOTE: This is not an officially supported Google product.


~53K SLoC