A robust Rust tool to edit JSON files with comments. It allows you to maintain a commented version of your configuration (.jsonc) while automatically generating a strict, clean JSON version (.json) for your applications.
- Edit with Comments: Write standard JavaScript-style comments (
//and/* */) in your JSON. - Auto-Strip: Automatically strips comments to generate valid JSON.
- Validation: Ensures your JSON is valid before saving the clean version.
- Editor Integration: Opens your default
$EDITOR(defaults tonano) or usesVISUAL.
# Edit a JSON file (preserving comments in a hidden or side-by-side .jsonc file)
jsonc config.json
# View the clean JSON output
cat config.jsoncargo install --path .- When you run
jsonc config.json, it opens the.jsoncversion of your file (where your comments live). - If the file is new, it creates it for you (after you save). If you have an existing
.jsonfile, it automatically creates a commented version so you can start editing immediately. - Collision Safety: If the target
.jsonfile does NOT exist, but a corresponding.jsoncfile DOES exist (e.g., from a naming collision), it will return an error to prevent accidental overwriting. - It opens the
.jsoncfile in your standard system editor. - Save and Close: When you are finished, just save and exit the editor.
jsoncwill automatically:- Validate your JSON.
- Save your comments to the
.jsoncfile. - Strip comments and save the clean JSON to your target file.
Tip: If you exit a new file without saving,
jsoncwill abort and nothing will be created.