#json-text #jsonc #comments #formatter #strip #authentication #debugging

app jcfmt

A command-line tool to format JSONC (JSON with Comments) text

3 releases

Uses new Rust 2024

0.1.2 Dec 11, 2025
0.1.1 Aug 17, 2025
0.1.0 Aug 16, 2025

#450 in Command line utilities

MIT license

24KB
609 lines

jcfmt

jcfmt Actions Status License

jcfmt is a command-line tool to format JSONC (JSON with Comments) text.

Before:

{"name":"example", // App name

// config and features
"config": {"debug":true, "port":8080/* TODO: fix later */},
"features": ["auth","logging"]  ,}

After:

{
  "name": "example", // App name

  // config and features
  "config": {
    "debug": true,
    "port": 8080 /* TODO: fix later */
  },
  "features": ["auth", "logging"],
}

Key Features

  • Comment-aware JSON formatting:
    • Supports both line comments (//) and block 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

Installation

$ 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

Examples

// 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"]
}

Dependencies

~220KB