Just Text Tool Blog

Format JSON for GitHub README (Improve Documentation Clarity)

2026-02-21 · 2 min read

Scope: writing readable JSON snippets for GitHub documentation.

TL;DR: Most parse failures come from a few repeat offenders: trailing commas, invalid quotes, invisible Unicode, and “almost JSON” that is actually a JS object literal. Fix syntax first, then validate and format.

Table of contents

Why this happens

JSON is strict. Copy‑pasting from docs/chats/word processors can introduce characters a parser rejects. If the line/column in the error message looks “wrong,” invisible characters earlier in the file are often the cause.

Example (Before → After)

Before

{"name":"app","version":"1.0.0","scripts":{"start":"node index.js"}}

After

{
  "name": "app",
  "version": "1.0.0",
  "scripts": {
    "start": "node index.js"
  }
}

Step-by-step solution

  1. Paste into a plain text editor (strip rich formatting).
  2. Fix the strict JSON rules (quotes, commas, keys).
  3. Remove invisible characters (zero‑width / NBSP / BOM) if the error seems off.
  4. Validate JSON once it looks correct.
  5. Format (beautify) for readability and safe sharing in docs.

Common mistakes

FAQ

Q: Why does this work in JavaScript but not in JSON.parse?
A: JS object literals allow more syntax than JSON.

Q: Do spaces/newlines break JSON?
A: Normal whitespace doesn’t, but hidden Unicode can.

Q: Should I minify or beautify?
A: Beautify for debugging/docs; minify for transport if needed.

Q: What is the fastest check?
A: Scan for trailing commas and quotes first.

Q: How do I prevent these issues?
A: Keep JSON in plain text sources, validate before commit/deploy.

Quick checklist

Related: /blog/



Related cluster (planned topics)

About

Just Text Tool is a text utility project focused on clean formatting, developer workflows, and practical writing improvements.