LinuxCommandLibrary

json5

Convert JSON5 data to JSON

TLDR

Convert JSON5 stdin to JSON stdout

$ echo [input] | json5
copy

Convert a JSON5 file to JSON and output to stdout
$ json5 [path/to/input_file.json5]
copy

Convert a JSON5 file to the specified JSON file
$ json5 [path/to/input_file.json5] --out-file [path/to/output_file.json]
copy

Validate a JSON5 file
$ json5 [path/to/input_file.json5] --validate
copy

Specify the number of spaces to indent by (or "t" for tabs)
$ json5 --space [indent_amount]
copy

Display help
$ json5 --help
copy

SYNOPSIS

json5 [options] [file]

PARAMETERS

--help
    Display help message and exit.

--version
    Display version information and exit.

-c, --compact
    Compact output, minimizing whitespace.

-p, --parse
    Parse the file, but do not format output.

-s, --space
    Specify the number of spaces to use for indentation. Default is 2.


    The input JSON5 file. If not specified, reads from standard input.

DESCRIPTION

The `json5` command is a versatile tool for working with JSON5 (JSON with human-friendly syntax) data from the command line. It provides functionalities similar to `jq` but specifically targets JSON5, allowing for parsing, querying, manipulating, and serializing JSON5 documents.
It can be used for tasks like extracting specific values from a configuration file, transforming data from one format to another, and validating JSON5 syntax. The command supports operations like filtering, mapping, reducing, and sorting, making it a powerful instrument for data processing within shell scripts and command-line workflows. While similar to `jq`, it offers the added benefit of handling the less strict JSON5 format, which includes features like comments and trailing commas.

ERROR HANDLING

The command returns a non-zero exit code if there are errors during parsing or processing. Check the error message on standard error for more details.

SEE ALSO

jq(1), jsonlint(1)

Copied to clipboard