JSON repair
Formatters
Loading
Loading tool
The tool is loaded only when you open it.
All processing for this tool happens in your browser. Your input is not sent to a server.
About this tool
Repair a copied configuration, API sample or generated JSON fragment in a local Web Worker using jsonrepair 3.15.0. The tool can add missing punctuation, quote keys, normalize single quotes and remove comments or trailing commas. It retains the original input and repaired text for comparison and shows one exact enclosing changed span. Repairs are guesses about syntax: a parseable result does not establish the intended data, restore missing content or validate a schema. Review every result before copying or downloading it.
Common uses
- Prepare a small JSON-like configuration containing comments, single quotes or unquoted keys for a strict JSON consumer.
- Inspect where a truncated response gains closing quotes, brackets or braces before asking its source for the complete data.
- Compare an AI-generated JSON fragment with a proposed repair without replacing the original text.
- Keep large integer identifiers and decimal or exponent spellings intact while repairing surrounding punctuation.
- Inspect an explicit conversion such as a JSONP wrapper, fenced JSON or newline-delimited records before choosing whether to use it.
How to use it
- 1.Paste the original text, or load a sample. Input is limited to 200,000 UTF-8 bytes. Run Repair JSON. The local worker attempts a bounded repair; cancel it if you no longer need the result.
- 2.Read the warnings and compare original and repaired text. Already-valid JSON stays exactly as entered unless a safety check rejects it. Inspect the changed span. Ranges are zero-based UTF-16 offsets with an exclusive end; emoji may occupy two code units. The span can contain unchanged text between separate edits.
- 3.Confirm the review checkbox to enable Copy and Download. Copy or download the reviewed repaired text. Editing the input invalidates the prior result; rerun the repair before exporting it.
Executable input and output examples
Remove comments and a trailing comma
{
// copied config
"name": "Ada",
"enabled": true,
}{
"name": "Ada",
"enabled": true
}The comment and final comma are removed. The blank line and other formatting shown here are retained exactly; the tool does not reformat the result.
Quote keys and single-quoted strings
{name: 'Ada', city: '東京'}{"name": "Ada", "city": "東京"}The keys and strings receive JSON double quotes. Japanese text is retained. This does not execute a JavaScript object literal.
Insert a missing comma
{"a": 1 "b": 2}{"a": 1, "b": 2}A comma is inserted between the properties. Check that these were meant to be separate fields.
Close a truncated nested value
{"user":{"name":"Ada","roles":["reader","editor"{"user":{"name":"Ada","roles":["reader","editor"]}}Only closing punctuation is supplied. Additional roles or fields that might have been cut off are not recovered.
Close a truncated string
{"message":"Hello{"message":"Hello"}The proposal contains "Hello", but the intended sentence may have been longer. Review the truncation rather than treating the output as recovered data.
Preserve numeric spellings during repair
{id: 9007199254740993, price: 1.2300, small: 1e-400, sign: -0,}{"id": 9007199254740993, "price": 1.2300, "small": 1e-400, "sign": -0}The large integer, trailing decimal zeros, exponent and negative zero remain exact text. A downstream JavaScript parser can still lose precision.
Leave accepted strict JSON unchanged
{
"id": 9007199254740993,
"price": 1.2300,
"small": 1e-400,
"sign": -0,
"escaped": "\u0061"
}{
"id": 9007199254740993,
"price": 1.2300,
"small": 1e-400,
"sign": -0,
"escaped": "\u0061"
}The output is exactly the input, including indentation, numeric lexemes and the backslash-u escape. No changed span is needed.
Remove a Markdown code fence
```json
{"ready": true,}
```
{"ready": true}
The fence and trailing comma are removed. The leading and trailing newline in the displayed output are part of the actual repaired text.
Strip a JSONP wrapper without running it
callback({"ok":true});{"ok":true}The callback name, parentheses and semicolon are removed as text. No callback is invoked; check whether extracting the inner value is what you intend.
Normalize Python-style constants
{'active': True, 'deleted': False, 'value': None}{"active": true, "deleted": false, "value": null}True, False and None become true, false and null. Single quotes are normalized too. This is a textual proposal, not Python execution.
Wrap newline-delimited records in an array
{"id":1}
{"id":2}[
{"id":1},
{"id":2}
]Two records become one JSON array. Review this structural change; use the JSON Lines tool for a dedicated line-oriented workflow.
Review an ambiguous bare word
{"state": pending}{"state": "pending"}pending is guessed to be a string. The tool cannot know whether a missing value, identifier or different state was intended.
Count offsets using UTF-16
{"emoji":"😀", unquoted: true,}{"emoji":"😀", "unquoted": true}The emoji stays unchanged and counts as two UTF-16 code units. The enclosing change starts after it; do not interpret offsets as byte counts.
Reject duplicate decoded keys
{"a":1,"\u0061":2}{
"error": "duplicate"
}Diagnostic code only: no repaired output is produced. The two key spellings both decode to a, so choosing a value requires a deliberate decision.
Reject an invented exponent
{"value":1e}{
"error": "numericChange"
}Diagnostic code only: no repaired output is produced. Completing 1e as 1e0 would invent part of the numeric token, so this proposal is blocked.
Supply a missing value as null
{"value":}{"value":null}The library proposes null for the missing value. This is an invented placeholder, not the recovery of an original value; check the source before accepting it.
A repeated comma can change array nesting
[1,,2]
[ [1],2 ]
For this ambiguous input, the library proposes an outer array containing [1] and 2, with the exact newlines shown. It does not merely remove the repeated comma or fill a missing element. The intended structure is unknown; inspect and correct the nesting before accepting the proposal.
Common errors and review points
- A duplicate error can be caused by escaped spellings of the same key. Remove or rename the conflicting property after checking which value belongs there.
- A numeric-change error is intentional protection. Correct malformed numeric literals from their source rather than assuming a guessed exponent or decimal is right.
- An empty-input error also applies to whitespace-only text. Paste a JSON value or a JSON-like fragment first.
- Byte limits count UTF-8 bytes, not visible characters. Chinese or Japanese text and emoji can reach the cap sooner than ASCII.
- A depth error can occur before repair finishes. Reduce excessive nesting instead of repeatedly retrying the same document.
- A syntax error means the repair library could not produce an accepted result. Inspect unmatched delimiters, invalid escapes and unexpected surrounding text.
- A successful repair of a cut-off string is not proof that the string is complete. Compare it with the original source.
- A wide change span can cover several separate corrections and unchanged interior text. It is not a count of edits.
- If a task times out or you cancel it, no result is available to export. Try a smaller fragment and review any omitted context.
- Raw malformed Unicode cannot be exported faithfully as UTF-8. Correct it at the source; do not confuse it with a literal backslash-u escape.
Limits and notes
- Input is capped at 200,000 UTF-8 bytes, output at 500,000 UTF-8 bytes and nesting at 64 levels. The browser terminates a repair worker after 5 seconds; this is not a streaming or large-file tool. Raw unpaired UTF-16 surrogates are rejected because a UTF-8 download would replace them. An already-escaped sequence such as "\uD800" is retained as text; downstream Unicode handling may differ.
- Syntax repair cannot recover omitted records, infer business meaning or prove an API payload is correct. A closed truncated string can still contain incomplete data. This is not a complete JSON5 parser, schema validator or general JavaScript interpreter. Some malformed inputs remain unsupported and return no repaired output. Unknown or incomplete escapes, undefined, ellipses and JavaScript expressions such as [2/3], [true&&false] or {x:true?false:null} are outside the supported repair profile. A missing value may be filled with null; this is a guessed placeholder, not recovered data.
- Duplicate decoded object keys are rejected, including "a" and "\u0061" in the same object. The tool does not silently retain the last value; the same key in separate objects is allowed. Numeric token spellings are checked before and after repair. A proposed numeric change, insertion or removal is rejected; examples include 01, 0x10, .5, 1. and an incomplete 1e. Valid numeric spellings such as 9007199254740993, 1.2300, 1e-400 and -0 are retained as text. A later JavaScript parser or another formatter can still round or normalize them.
- The displayed difference is a single minimal enclosing changed span based on the common prefix and suffix, not a list of independent edits or a semantic JSON diff. Unchanged text inside that span is included.
- JSONP removal, Python constant conversion, code-fence removal, NDJSON wrapping and bare-word quoting can change how the text is interpreted. These are proposals to review, not evidence of the author’s intent. The tool does not execute JavaScript, evaluate JSONP callbacks, resolve URLs, fetch data or store the input in browser storage. Copy and download happen only when requested.
Frequently asked questions
Can repair recover all data or validate my payload?
No. It can sometimes add closing punctuation or finish a string delimiter, but missing bytes, records and values cannot be recovered. Compare the proposal with the source and obtain a complete response when correctness matters. No. Success means the proposed output passed this tool’s syntax and safety checks. Required fields, types, ranges and application rules need separate validation; use the JSON Schema validator when you have a schema.
How are duplicate keys, large numbers and numeric repairs handled?
Already-valid accepted JSON is returned as the exact same text. During repair, numeric spellings are compared and preserved; the output is not produced by parsing and serializing numeric values. Surrounding syntax, comments and whitespace can change. Review the exact output before using another parser. Consumers can disagree about repeated member names and many silently keep the last value. This tool rejects duplicates after decoding key escapes, so {"a":1,"\u0061":2} is not accepted. Choose the intended value yourself. Changing .5 to 0.5 or completing 1e as 1e0 changes a numeric token. This tool refuses proposed numeric-token changes instead of guessing or silently converting the token into a string.
What do the change-span offsets mean?
They count UTF-16 code units from zero, with the end position excluded. A typical emoji counts as two units. One enclosing before/after span covers all changes, so unchanged text between changes can appear inside the displayed span.
Does the tool execute code, upload input or save it?
No code runs. The repair library can strip a JSONP callback wrapper and rewrite True, False and None as JSON literals. These textual transformations still require review because JSON syntax alone cannot establish the desired meaning. It stays in the current page’s memory and remains available for comparison with the output. The repair path sends it only to a local worker, with no network calls, code evaluation or browser-storage writes. Clearing the tool removes its current input and result.
- jsonrepair · official project and supported repairs
- RFC 8259 · JSON grammar, numbers and member names
- MDN · JavaScript string length and UTF-16 code units