pipr.tools

json-format

Pretty-print JSON

⟐ Data

Try it

stdin0 chars
stdout0 chars

Flags

--indent number default: 2

Example

Pretty-print a compact JSON object

Usage
$ echo "{"name":"Alice","age":30,"roles":["admin","editor"]}" | json-format
View source
(input, opts = {}) => {
      try {
        return JSON.stringify(
          JSON.parse(input),
          null,
          parseInt(opts.indent) || 2,
        );
      } catch (e) {
        return `Error: ${e.message}`;
      }
    }

Suggested Pipelines

Related Tools