How to format JSON safely at work
Pasting a production API response into a random “JSON beautifier” is the quiet data-leak nobody writes a policy about. Here is what is actually in that payload — and how to fix the parse errors.
Pasting a production API response into a random “JSON beautifier” is the quiet data-leak nobody writes a policy about. Here is what is actually in that payload — and how to fix the parse errors.
An API response is rarely just a list of product names. It usually carries access tokens in test headers, internal hostnames, customer email addresses, order identifiers, feature-flag names that reveal unreleased work, and sometimes full personal records. A formatter site is a server that receives that text; even with a “we delete it after an hour” promise, you have no way to verify it.
This is why many security teams now treat clipboard-to-website tools as they treat USB sticks: fine
in principle, banned by default. The easy fix is to use a formatter that never makes a network
request — the JSON Formatter here runs the browser’s own
JSON.parse, so the payload stays inside the tab.
{
"name": "Ada",
"role": "engineer",
} ← this comma is fatal in strict JSON
JavaScript allows it, JSON does not. It is the single most common cause of “Unexpected token }”.
{ name: 'Ada', role: "engineer" } ← neither key nor value is valid JSON
JSON requires double quotes around every key and every string value. Both styles come from copying a JavaScript object out of a console or a code example.
{
// TODO: remove before prod
"debug": true
}
JSON has no comment syntax. Some tools (JSONC) accept it; the standard does not, and neither does
JSON.parse.
Copying from Word, Slack or a PDF can bring along smart quotes (“ ”), non-breaking spaces
or a byte-order mark. They look identical on screen and break parsing at a position that appears
empty. If the error points at whitespace, retype the quotes.
Modern browsers are helpful but terse. A message like:
Unexpected token '}', ..."items": [1,2,3,]" is not valid JSON
points at the character after the problem. The real culprit is the comma immediately before it. General rule: the mistake is usually a few characters before the reported position.
The MySelfPDF formatter converts the browser’s position into a line and column and prints the source line with a caret, which turns a five-minute hunt into five seconds:
line 12, column 3
]
^ Expected double-quoted property name
“Repair” rewrites the four problems above into strict JSON — trailing commas removed, single quotes
converted, unquoted keys quoted, comments stripped. It works on a scanner rather than regex, so a
comma inside a string such as "a,b,c" is never touched.
It will not fix everything. Do not expect it to handle:
[ ] and add commas firstLine/column errors, tree view, repair, sort and minify — all local.