Open malformed JSON
A JSON file with a syntax error still opens in JSON Digger. You see the document up to the error, and the status bar tells you where the error is. When opening or pasting JSON fails, JSON Digger can also offer to repair it into a valid copy.
How a malformed file opens
Section titled “How a malformed file opens”JSON Digger reads the file up to the first syntax error and stops there:
- The tree shows everything before the error. Objects and arrays that are still open at the error end there.
- The status bar shows
Malformed JSON @ byte Nin red, whereNis the position of the error in bytes from the start of the file. Hover over it to read the parser’s message.
In a large file, the error can show up a few seconds after the file opens, when background indexing reaches it.
To see the text around the error, open the file in a text editor that can go to a byte offset.
What works on a malformed file
Section titled “What works on a malformed file”| Feature | On a malformed file |
|---|---|
| Tree, search, copy | Work on the part before the error |
| Lint | Checks the part before the error; the Anomalies panel says “Malformed input from byte N: later values were not checked” |
| Editing | Not available: “The file is not valid JSON.” |
| Save As | Copies the file byte for byte, so the copy has the same error |
| Save Formatted Copy | Fails at the error, and no file is written |
To make the file editable, fix the error in a text editor and open it again.
Repair malformed JSON
Section titled “Repair malformed JSON”When opening a JSON file or pasting from the clipboard fails with a syntax error, the error notice can offer Repair. Select it to open a repaired copy of the text in a new tab; the original is not changed. JSON Digger confirms with “File repaired and opened” or “Clipboard JSON repaired and opened”. If the text cannot be repaired, it shows “Repair failed:” followed by the reason.
The repair rewrites the text into valid JSON. It fixes these problems:
| Problem | Repair |
|---|---|
// and /* */ comments |
Removed |
Trailing commas, [1, 2,] |
Removed |
| Missing commas between values | Added |
Single-quoted strings, 'text' |
Changed to double quotes |
Unquoted keys, {name: 1} |
Quoted |
= instead of :, or a missing : |
Changed to : |
undefined, NaN, Infinity |
Changed to null |
| Raw tabs or line breaks inside strings | Escaped |
| A string, object, or array cut off at the end of the file | Closed |
Other bare words, such as True or None |
Changed to strings: "True", "None" |
Check the result before you rely on it:
- Only the first value is kept. Anything after it, such as the second record of NDJSON pasted as JSON, is dropped.
TrueandFalsebecome strings, not booleans.- Text cut off right after a key, and numbers such as
+1,.5, or hexadecimal values, cannot be repaired.
Save the repaired document
Section titled “Save the repaired document”The repaired copy opens in a new tab with the same name as the original file. It exists only in memory until you save it.
The repaired document is read-only. To keep it, press Ctrl+Shift+S or choose File → Save As…, and pick a file name; the dialog suggests output.json. JSON Digger writes the JSON minified, with the keys in their original order. Open the saved file to edit it, or use Save Formatted Copy on it for indented JSON.