jcfmt is a command-line tool to format JSONC (JSON with Comments) text.
Before:
After:
{
"name": "example", // App name
// config and features
"config": {
"debug": true,
"port": 8080 /* TODO: fix later */
},
"features": ["auth", "logging"],
}- Comment-aware JSON formatting:
- Supports both line comments (
//) and block comments (/* */)
- Supports both line comments (
- Trailing comma preservation:
- Maintains trailing commas in arrays and objects when present in the input
- Character preservation:
- Only whitespace is adjusted
- All printable characters maintain their original order
- Content-aware newline insertion:
- Uses multiline formatting when input contains newlines or comments within arrays and objects
- Blank line preservation:
- Maintains blank lines when there are multiple successive newlines in input
$ cargo install jcfmt
$ jcfmt -h
A command-line tool to format JSONC (JSON with Comments) text
Usage: jcfmt [OPTIONS]
Options:
--version Print version
-h, --help Print help ('--help' for full help, '-h' for summary)
-s, --strip Remove all comments and trailing commas from the JSON output// Simple example
$ echo '{/*foo*/"bar":"baz"}' | jcfmt
{ /*foo*/
"bar": "baz"
}
// Complex example
$ cat example.jsonc
{"name":"example", // App name
/* config and
features */
"config": {"debug": true, "port": 8080 /* TODO: fix later */},
"features": ["auth", "logging", ],
}
$ cat example.jsonc | jcfmt
{
"name": "example", // App name
/* config and
features */
"config": {
"debug": true,
"port": 8080 /* TODO: fix later */
},
"features": ["auth", "logging",],
}
// The `--strip` flag produces plain JSON output
$ cat example.jsonc | jcfmt --strip
{
"name": "example",
"config": {"debug": true, "port": 8080},
"features": ["auth", "logging"]
}
{"name":"example", // App name // config and features "config": {"debug":true, "port":8080/* TODO: fix later */}, "features": ["auth","logging"] ,}