by JSONBeauty (LX AI)

Last updated: 2026-10-03

Pretty-print JSON with a clear error location

Why I built JSONBeauty

I work on micro‑services that exchange JSON over HTTP. When a payload arrives minified it is a wall of text. I need to see the structure quickly, and when the payload is broken I need to know exactly where the parser choked. Existing online formatters either hide the error or require uploading data to a third‑party site. I wanted a tool that runs locally, shows a clean indented view, and points to the offending character with line and column numbers.

Pain points with minified payloads

Existing tools fall short

How JSONBeauty works

The core is a thin wrapper around the built‑in JSON.parse in Node and the browser. I first attempt to parse the string. If it succeeds I run a recursive pretty‑printer that inserts line breaks and a two‑space indent. If parsing fails I catch the exception, extract the offset reported by the engine, and translate that offset into a line/column pair. The output then shows the original text with a marker under the problematic character and a short message.

Parsing step

I rely on the engine’s own parser because it is battle‑tested and follows the ECMAScript specification. This means I inherit the same error locations that JSON.parse provides, which are accurate for the vast majority of malformed inputs I have seen in the wild.

Error detection and location

When JSON.parse throws, the exception object contains a message string and, in V8‑based engines, a stack that includes the character index. I parse that index, count newline characters to get the line number, and compute the column as the distance from the line start. I then slice the original string into three parts: before the error, the offending character, and after the error. I wrap the offending character in a <strong> tag for visual emphasis.

Pretty‑print formatting

The formatter walks the parsed value depth‑first. For objects it prints each key on its own line, adds a colon, a space, then the formatted value. For arrays it prints each element on its own line. Indentation increases by two spaces for each nesting level. Strings are output with double quotes and escaped as needed. Numbers, booleans and null are printed literally.

Using the CLI

JSONBeauty ships as a single binary jsonbeauty that works on macOS, Linux and Windows. It reads from stdin or a file path and writes to stdout unless you specify an output flag.

Installation

Download the pre‑built archive from the releases page, extract the binary, and place it somewhere on your PATH. No Node installation is required because the binary bundles the runtime.

Basic command

jsonbeauty < payload.json

If the input is valid you will see a nicely indented version. If it is invalid the program prints an error line like:

Error at line 12, column 7: unexpected token '}'

Options for indent and error output

Using the browser widget

For quick checks I provide a tiny script that you can drop into any page. It adds a textarea, a button and a preview pane. The widget runs entirely in the client, so no data leaves your machine.

Embedding the script

Add the following line before the closing </body> tag:

<script src="https://unpkg.com/jsonbeauty@latest/dist/widget.js"></script>

Live preview

Paste or type JSON into the left textarea. As you type the widget attempts to parse on each keystroke. If the text is valid the right pane shows the pretty‑printed version with two‑space indent. If it is invalid the pane shows the original text with a red underline under the first offending character and a tooltip with line/column.

Copy‑to‑clipboard

A button beneath the preview copies the formatted output to the clipboard. The widget also offers a “Download” link that saves the pretty‑printed text as a file with a .json extension.

Integrating with API testing

I use JSONBeauty in my test pipelines to catch malformed responses early. The tool can be invoked as a step in a shell script or as a Node module.

Pre‑request validation

Before sending a request I sometimes need to ensure a JSON payload I constructed is well‑formed. I pipe the payload through JSONBeauty and check the exit code. A non‑zero exit means I have to fix the source before the request goes out.

Post‑response pretty‑print

After receiving a response I pipe the body through JSONBeauty. If the service returns valid JSON I get a readable log entry. If the service returns broken JSON I get an error line that I can attach to a bug report.

Logging malformed payloads

In a long‑running service I redirect stderr to a log file. JSONBeauty’s error messages include a timestamp when invoked from a wrapper script, making it easy to correlate malformed inputs with specific requests.

Performance notes

Below is a simple comparison of runtime for different input sizes on my laptop (Node 20, Chrome 124). Times are wall‑clock averages of ten runs.

Payload size Node (ms) Browser (ms)
10 KB 2.3 1.9
100 KB 4.1 3.6
1 MB 12.8 11.4
5 MB 68.5 62.0

What this is NOT

I want to be clear about the limits of JSONBeauty so you do not rely on it for things it was not designed to do.

No guarantee of catching every semantic error

The tool only checks syntactic validity. It will not tell you if a required field is missing, if a number is out of range, or if a date string does not match the expected format. Those checks belong in a schema validator or unit tests.

Not a full JSON Schema validator

If you need to validate against a JSON Schema draft you should use a dedicated library such as AJV (https://ajv.js.org/json-schema.html). JSONBeauty does not evaluate keywords like required, minimum or pattern.

Does not replace unit tests

Automated tests should assert the shape and meaning of your data. JSONBeauty is a convenience for manual inspection and quick sanity checks, not a substitute for a test suite.

Operator checklist for Pretty-print JSON with a clear error location

I keep a written checklist next to every release that touches this topic. The list is boring on purpose: name the owner, name the evidence artifact, and name the rollback. If a step cannot produce a file, a ticket, or a log line, it is not a step — it is a wish.

Before you change production

While you run the check

After you finish

SignalWhat to recordStop-ship?
Unexpected write or sendTool name, args, identityYes until gated
Missing confirmation on destructive actionCall path and bypassYes
Untrusted text treated as instructionSource surface and resulting actionYes for agent reach
Scanner clean, judgment openDeferred items + ownerOnly if core path safe

jsonbeauty helps with the measurable first pass. Architecture choices, legal sign-off, and customer-facing claims still need a human owner. Treat every checklist row as decision support, not a certificate.

How I explain limits to buyers

When a prospect asks whether the product "covers everything," I answer with the boundary: automated checks catch known patterns; novel chains and policy judgment still need review. That honesty keeps support load down and keeps the blog aligned with what the product actually does.

If you need a second opinion, pair this write-up with the references below and with your own staging reproduction. Do not skip the reproduction step just because a model wrote a confident summary.

References

Frequently asked questions

What is Pretty-print JSON with a clear error location?

Minified API payloads are unreadable. JSONBeauty formats them or tells you where the parse failed.

References

Want to try the product? JSONBeauty

Generated 2026-09-17 · primary sources only · no fabricated traffic metrics