LinuxCommandLibrary

jsonlint

Validate JSON data syntax and format

SYNOPSIS

jsonlint [options] [input_file]

PARAMETERS

-v, --version
    Show program's version number and exit

-q, --quiet
    Quiet mode. Suppress warnings.

-s, --sort-keys
    Sort the output JSON object keys alphabetically.

-S SEPARATOR, --separator=SEPARATOR
    Use SEPARATOR to separate object members. (Default: ': ')

-t INDENT, --indent=INDENT
    Use INDENT to indent object members. (Default: ' ')

-w WIDTH, --max-width=WIDTH
    Wrap output at this width (default: don't wrap)

-S SEPARATOR, --separator=SEPARATOR
    Use SEPARATOR to separate object members. (Default: ': ')

-V, --validate
    Validate JSON only and don't format. (Default)

-S SEPARATOR, --separator=SEPARATOR
    Use SEPARATOR to separate object members. (Default: ': ')

--color
    Colorize invalid JSON output

--nocolor
    Force no color output

--json-lines
    Parse a JSON Lines file (one JSON object per line)

-f, --format
    Format JSON only and don't validate.

--no-format-on-error
    Disable formatting of JSON even if the file is valid.

input_file
    Path to the JSON file to validate/format. If omitted, reads from standard input.

DESCRIPTION

jsonlint is a command-line tool for validating and formatting JSON (JavaScript Object Notation) files.
It checks JSON syntax according to RFC 4627 or RFC 7159, reporting any errors it encounters.
Beyond validation, it can also reformat JSON, applying consistent indentation and spacing for improved readability.
This is particularly useful for large or complex JSON files where manual inspection can be difficult.
Using jsonlint helps ensure that JSON data is well-formed and can be reliably processed by other applications and services, preventing parsing errors. It supports both standard input and file input, making it versatile for different usage scenarios.

CAVEATS

jsonlint relies on the Python interpreter to be present on the system if it is the Python version.
Performance may be affected by the size of the JSON file. Very large files may take a significant amount of time to process.

EXIT CODES

jsonlint returns 0 if the JSON is valid, and a non-zero exit code if validation fails. This makes it suitable for scripting and automated workflows.

HISTORY

The jsonlint command is available both as part of Python and NodeJS ecosystems.
It was created to ease the process of validating JSON files and formatting them.
It has become a standard tool for developers working with JSON data. The usage has increased with more usage of REST APIs and file sharing using JSON objects.

SEE ALSO

jq(1), python(1)

Copied to clipboard