jcfmt

Crates.iojcfmt
lib.rsjcfmt
version0.1.1
created_at2025-08-16 05:50:02.412094+00
updated_at2025-08-17 10:42:24.133302+00
descriptionA command-line tool to format JSONC (JSON with Comments) text
homepagehttps://github.com/sile/jcfmt
repositoryhttps://github.com/sile/jcfmt
max_upload_size
id1798033
size26,603
Takeru Ohta (sile)

documentation

README

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"]
}
Commit count: 0

cargo fmt