json_pp
Pretty-print JSON data
SYNOPSIS
json_pp [options] [file]
PARAMETERS
--json_opt OPTION=VALUE
Pass an option directly to the JSON module. Can be specified multiple times.
--indent n
Set the indentation level to n spaces (default: 2).
--color
Enable colored output.
--no_color
Disable colored output.
--sort_keys
Sort the keys of JSON objects alphabetically.
--allow_nonref
Allow non-reference values to be encoded. Usually not recommended.
file
Optional: The path to a JSON file to read. If omitted, reads from standard input.
DESCRIPTION
json_pp is a command-line utility designed to take JSON data as input and output it in a human-readable, pretty-printed format. This is extremely useful for debugging, examining complex JSON structures, and making JSON data easier to understand.
It helps to format JSON on the command line, rather than having to import the JSON and print it with scripting languages like Python or Javascript. The utility typically reads JSON from standard input, but can read from a file. It supports options for controlling indentation and color output, allowing you to customize the output for your specific needs. Because json_pp is part of the Perl JSON module, it is widely available. It relies upon the CPAN perl JSON package.
CAVEATS
Requires the Perl JSON module to be installed. Color output relies on ANSI terminal support.
EXAMPLE USAGE
To pretty print a JSON file: json_pp data.json
To pretty print JSON from standard input, and specify four spaces as indentation:cat data.json | json_pp --indent 4
To enable colored output:cat data.json | json_pp --color
HISTORY
json_pp is bundled with the Perl JSON module from CPAN. The JSON module has existed since the mid 2000's. The command has become a standard tool for command-line JSON processing on Linux and other Unix-like systems, especially where Perl is readily available.
Its usage is tied to the adoption of JSON as a primary data exchange format, especially in web services and configuration files.
SEE ALSO
jq(1), python -m json.tool(1)