ERROR: Invalid JSON on Mac: Find the Line or Repair It
"ERROR: Invalid JSON" with no line number? See the usual causes, find the exact line and column on your Mac, or repair broken JSON in Bytepliers.
TroubleshootingUpdated 7 min read
On this page
You pasted 30 lines of JSON into a tool, and all it said was:
ERROR: Invalid JSONNo line, no column, no hint. People on Boop's issue tracker have asked for exactly this: details like jsonlint gives. This page shows the usual causes, how to find the spot, and how to repair the safe problems automatically.
Why a formatter says only "Invalid JSON"
A strict JSON parser stops at the first character it can't accept. A tool that only reports pass or fail throws that position away. The cause is almost always one of these, most common first:
- Text that is valid JavaScript or Python, not JSON. RFC 8259 says the literal names must be lowercase, so
True,Noneandundefinedfail. It also says values such as Infinity and NaN are not permitted. - Trailing commas, comments, single quotes and unquoted keys. These are fine in JavaScript objects and many config files, and invalid in JSON.
- A missing comma, colon or bracket. Parsers usually report this at the next token, not where you forgot it.
- Raw control characters inside a string. The spec says control characters (U+0000 through U+001F) must be escaped, so a literal tab or line break inside quotes is an error.
- Invisible characters from a copy-paste. Zero-width spaces and non-breaking spaces are invisible, and the parser still rejects them. A byte order mark at the start is a related case.
- It isn't JSON at all. An HTML error page from an API, YAML or CSV will never pass.
The RFC is the JSON specification (RFC 8259) if you want the exact grammar.
Fix 1: Find the line and column in Bytepliers
- Open Bytepliers and choose JSON Formatter in the sidebar, or press ⌘1 (Command-1).
- Paste into the JSON input pane with ⌘V, or use Paste from Clipboard. You can also drop a file on the editor or press ⌘O.
- Look for the markers: a red tint on the error line, a dotted underline at the column, a ⚠ Ln 3:7 badge, and a status line such as "Ln 3, Col 11 · message". The line-number gutter shows a red dot on the error line.
- Fix the marked spot, then check the line before it. A missing comma tends to be reported at the next key.
If the gutter is hidden, use View ▸ Toggle Line Numbers (⌃⌘L).
The parsing menu in the toolbar has two settings: Lenient (the default, "repairs broken JSON") and Strict ("RFC 8259 only"). Use Strict when you want to see what an API or config loader would reject. If Lenient could parse your text, Strict shows a Switch to Lenient button.
Fix 2: Repair the JSON with Lenient mode
Use this when the text came from a log, a Python print, a JavaScript object literal or a config file with comments, and you want valid JSON out of it.
- In the parsing menu, choose Lenient.
- Paste your text. The output is strict JSON.
- Click Repaired N issues. The popover lists each fix with its Ln:Col and ends with "N fixes · output is strict JSON".
- Copy the result with ⇧⌘C.
What Lenient mode repairs and what it doesn't
| What's in your text | Example | Repaired in Lenient mode? |
|---|---|---|
| Comments | // note | Yes |
| Trailing comma | {"a": 1,} | Yes |
| Single quotes | {'a': 1} | Yes |
| Unquoted or numeric keys | {a: 1} | Yes |
| Python or JavaScript literals | True, False, None, undefined | Yes |
NaN or Infinity | {"a": NaN} | Yes |
| Smart quotes | {“a”: 1} | Yes |
| Raw control characters in strings | a literal tab inside quotes | Yes |
| Document wrapped in a string or backslash-escaped | "{\"a\": 1}" | Yes |
| Missing comma, missing or extra bracket | {"a": 1 "b": 2} | No: use the error marker and fix by hand |
| Invisible characters from a web page or chat | zero-width space | No: see Fix 3 |
For NaN and Infinity, the NaN and Infinity option decides the output: As strings (default) or As null.
Fix 3: The marker points at a line that looks fine
Text pasted from web pages, chat apps and PDFs can carry zero-width characters and non-breaking spaces. They look like nothing, and parsers reject them.
- Paste the text into the String Inspector tool (Inspect group).
- Invisible characters are highlighted, and the stats include a count of them.
- Click Remove Invisibles, copy the cleaned text, and paste it back into JSON Formatter.
Fix 4: Get a line and column from Terminal
If python3 is available on your Mac, Terminal can also report a position. Copy the JSON, then run:
pbpaste | python3 -m json.toolThis reads the clipboard and prints formatted JSON, or an error that includes the line and column. It changes nothing, so there is nothing to undo. On a Mac without developer tools installed, macOS may offer to install them the first time you run python3. Python's parser is strict and won't repair anything, so this is for locating the error only.
Other reasons a validator rejects your file
A file of one-object-per-line
A validator may reject a file even though every line is valid JSON. That is NDJSON (JSON Lines): one document per line, no surrounding array. JSON Formatter detects several documents separated by line breaks. It offers One per line (default) or Wrap as array, and the status line reads "N documents · N values". Choose Wrap as array if the consumer expects a single array.
Quick Panel or Detect & Replace won't repair it
If you pressed ⌥⌘B (Quick Panel) or ⌥⇧⌘B (Detect & Replace Clipboard) on broken JSON, you may see "Nothing recognised on the clipboard." Both use the strict JSON parser, so repaired JSON falls through. Paste the text into JSON Formatter in the main window instead, where Lenient mode applies.
Too big or too deep
| Limit | What happens |
|---|---|
| Nesting deeper than 100 levels | "Nesting too deep" |
| Input over 64 MB | Refused by JSON Formatter |
| File over 50 MB | Asks for confirmation before opening |
| File over 256 MB | Refused |
Checklist before you try again
- The parsing menu is on Lenient if you want repairs, or Strict if you want to see what a strict parser would reject.
- You checked the line before the marked line for a missing comma or bracket.
- You ran the text through String Inspector if the marked line looks correct.
- You are copying the output pane (⇧⌘C), not your original text.
- The text is actually JSON, not YAML, CSV or an HTML error page.
If nothing works
Check Troubleshooting Bytepliers for size limits and other messages. If the marker or repair behaves wrongly, use Help ▸ Send Feedback… in the app, which fills in the app version and build, or go to MacSuite support. Include your macOS version, the exact status-line message and a small sample of the JSON with any secrets removed.
Subject: JSON Formatter marks the wrong spot / repair fails
Bytepliers version: (from About Bytepliers)
macOS version:
Parsing mode: Lenient / Strict
Status line text: (e.g. "Ln 3, Col 11 · message")
What I expected:
What happened:
Steps I tried: String Inspector, Strict mode, python3 -m json.tool
Sample JSON (secrets removed): attachedWhich tool to use
Boop is free and open source, and it is enough for quick text transforms. The python3 command above is a free way to get a line and column. Bytepliers fits when you want the marked line and a list of repairs in one window. It needs macOS 14 Sonoma or later and works offline. It is part of MacSuite, and you can try it free for 7 days. The JSON Formatter doc page covers the filter bar and tree view, and How to Format JSON on Mac covers other methods.
Common questions
Does my JSON leave my Mac?
No. The tools run on your Mac and the apps never send your files to us. The one exception is Open URL or cURL, which sends a request only when you click Send.
Is the repaired JSON safe to use?
Check the Repaired N issues list first. It shows every fix with its position, so you can confirm each one matches what you meant.
Lenient mode accepted my text, but my own parser rejects it. Why?
Lenient repairs your input before formatting. Copy the output, which is strict JSON, not your original. Switch to Strict to see what an RFC 8259 parser complains about.
Can Bytepliers repair a missing comma or bracket?
No. Those are not on the repair list. The error marker shows where the parser gave up, and you fix it by hand.