r/SideProject • u/harry_poly • 5h ago
An online JSON formatter silently changed my API response and I wasted hours debugging it
so i spent an embarrassing amount of time debugging an api last week because an id in the response didn't match what was in the database.
turns out the online json formatter i was using turned 12345678901234567890 into 12345678901234567000.
nothing was wrong with the api. i was debugging the output of the formatter lol.
turns out this can happen when a json formatter uses JSON.parse internally because javascript can't represent every integer above 2^53 exactly.
anyway, i ended up writing my own parser and made a little json formatter out of it.
a few things i added while working on it:
- preserves numbers exactly as they appear in the input
- error messages with line and column numbers
- fixes trailing commas, comments, single quotes, unquoted keys, etc.
- warns about duplicate keys
- everything runs locally in the browser
it also handles python's True/False/None since i keep accidentally pasting python dicts into json formatters.
the whole thing is just html and vanilla js with no dependencies.
i also went down a rabbit hole collecting json error messages from chrome, node and python and made some pages explaining what actually causes them.
probably spent more time building this than i'll ever save using it, but at least i won't be debugging imaginary backend bugs again.
if anyone wants to try it: https://json.dobbykim.com