JSON is everywhere, but most developers only use JSON.parse() and JSON.stringify(). Here are a few tricks worth knowing.
1. Pretty-print in one line
console.log(JSON.stringify(data, null, 2));
The third argument is your indent size. Instant readability.
2. Filter keys on stringify
JSON.stringify(user, ['name', 'email'], 2);
Pass an array of keys to only include those fields. Great for logging without exposing sensitive data.
3. JSONPath for deep queries
Instead of chaining .map() and .filter(), JSONPath lets you query nested JSON like a database:
$.users[?(@.age > 30)].name
4. Auto-repair broken JSON
LLMs often return slightly malformed JSON — trailing commas, single quotes, missing brackets. Instead of debugging it manually, a repair function can fix most common issues automatically.
5. Reduce LLM token usage with compact formats
If you're passing large JSON payloads as context to GPT or Claude, consider stripping whitespace at minimum. Better yet, look into TOON (Token-Oriented Object Notation) — a compact alternative that cuts token count by 30–60% without losing structure.
I built jsonindenter.com as a free client-side toolkit that covers all of the above — JSONPath tester, JSON repair, TOON converter, Zod/Pydantic generators, JWT tools, and more. No sign-up, no ads, your data never leaves your browser.
What JSON tricks do you swear by? Drop them in the comments 👇
Top comments (0)