Command Line Interface
What the json-6 package command line tool actually does: one flag, one job, converting .json6 files to JSON.
TL;DR: The json-6 npm package ships one executable with one option: -c, which compiles each .json6 file to a sibling .json file using 4-space indentation. There is no validate mode, no stdin, no output path and no --help. This page documents the real behavior, tested against json-6 1.1.7 on Node 24.
Install and Run
The CLI is lib/cli.js inside the json-6 package. Install it globally or per project:
# global npm install -g json-6 # or per project, run through npx npm install --save-dev json-6 npx json-6 -c config/app.json6 The command is json-6, not json6. The package declares "bin": "lib/cli.js" as a plain string, and npm then names the executable after the package: json-6. The README and the tool's own usage message both say json6, and that name does not exist after install (node_modules/.bin contains json-6, json-6.cmd and json-6.ps1). To get the shorter name, add your own "bin" alias in a wrapper package or use a shell alias. The FAQ covers other naming quirks.
You can always bypass the shim and call the script directly with Node, which is also the most portable form inside a build script:
node node_modules/json-6/lib/cli.js -c config/app.json6Usage and Flags
Running it with no arguments, with any first argument other than -c, or with -c and no files prints this to stderr and exits with code 1:
Usage: json6 -c path/to/file.json6 ... Compiles JSON6 files into sibling JSON files with the same basenames.| Argument | Meaning |
|---|---|
-c | Compile. Must be the first argument. The only flag the tool understands. |
file ... | One or more paths, relative to the current directory. Each is read as UTF-8 and parsed with JSON6.parse. |
That is the entire interface. The source says as much: a comment in cli.js calls it "pretty minimal for now" and lists output path and watch mode as open ideas. Unlike the CLI in the JSON5 package, it has no validate flag, no custom indent and no output file option.
What It Writes
For each file the tool strips a trailing .json6 from the file name, appends .json, and writes the result into the same directory. Indentation is always 4 spaces and the file ends with one newline. The serialization uses the native JSON.stringify, so the output is strict JSON. Given this app.json6:
{ // build settings name: 'x', n: 1_000, bin: 0b11, t: `a b`, u: undefined, a: [1,,2], }json-6 -c app.json6 writes app.json:
{ "name": "x", "n": 1000, "bin": 3, "t": "a\nb", "a": [ 1, null, 2 ] }Comments disappear, numbers are converted by value, the multi-line back-tick string becomes an escaped string, the undefined member is omitted and the empty array member becomes null. These are all consequences of going through a JavaScript value and then JSON.stringify; see the online converter for the same behavior interactively.
- Existing files are overwritten without warning. If
app.jsonexists, it is replaced. - The extension is only stripped if it is exactly
.json6. A file namednotes.txtproducesnotes.txt.json. - Files are processed in the order given. The first failure stops the run; files earlier in the list have already been written.
- Key order in the output is the key order of the parsed object, which follows the source for ordinary keys.
Exit Codes and Errors
The tool does not catch errors. It sets exit code 1 itself for bad usage, and for everything else it relies on Node's behavior for an uncaught exception. Tested results:
| Situation | Exit code | What you see |
|---|---|---|
| All files compiled | 0 | Nothing on stdout or stderr |
No arguments, wrong first flag, or -c with no files | 1 | The two-line usage text on stderr |
| A file does not exist | 1 | Node ENOENT stack trace |
| A file is not valid JSON6 | 1 | Stack trace whose message ends with [line:column]; no .json is written for that file |
A syntax error looks like fault parsing 'b' unexpected at 6 (near ':1 [b]:2}') [1:6]. The bracketed numbers are the 1-based line and column. The stack trace is noisy but the message line is enough to fix the file. For friendlier output paste the file into the online validator.
Using It in a Build
Because the tool only compiles, it fits best as a pre-build step that turns hand-edited .json6 sources into plain JSON for programs that cannot read JSON6:
{ "scripts": { "prebuild": "node node_modules/json-6/lib/cli.js -c config/app.json6 config/routes.json6" } }Commit the .json6 source and either commit or git-ignore the generated .json. Remember the generated file is overwritten on every run.
To validate without writing anything, parse in a one-liner. This uses the library directly and exits non-zero on failure:
node -e "require('json-6').parse(require('fs').readFileSync(process.argv[1],'utf8'))" config/app.json6Be aware that JSON6.parse reads the first value and ignores trailing text, so this one-liner accepts {a:1}x. The online validator also checks for trailing content. If you need that in a script, use the streaming parser JSON6.begin(), covered on the streaming page.
If you would rather not convert at all, load JSON6 directly in Node with the require hook or the ESM loader registration described in the Node.js guide.
FAQ
Why does json6 say command not found?
The installed executable is named json-6, after the package. The json6 name in the README and usage text does not exist after an npm install. Use npx json-6 or node node_modules/json-6/lib/cli.js.
Can it format or minify JSON6?
No. It only converts to JSON. Use the online formatter or call JSON6.stringify in a script.
Can I change the indentation or output path?
Not with the current tool; both are hard-coded (4 spaces, same directory). Write a few lines of Node using JSON6.parse if you need more control.
Does it read from stdin?
No. It only accepts file paths.
Is there a watch mode?
No. The source lists it as a possible future feature.
Convert Something
Try the conversion interactively before wiring it into a build.