JSON Repair Tool
Automatically fix and recover broken or malformed JSON—securely, quickly, and for free.
This tool repairs broken or invalid JSON using automated error correction. It targets the most common syntax problems found in exported data, logs, or hand-edited files—like missing quotes, stray commas, or mismatched brackets—and produces valid, parsable JSON as output.
Repair your JSON below
How JSON Repair Works
The tool scans your input for typical JSON syntax problems and applies targeted fixes, producing valid JSON when possible.
- Parses the input and locates common syntax errors, including illegal characters, misplaced brackets, and incorrect string quotes.
- Applies fixes for frequent mistakes—like adding missing quotes, removing trailing commas, or correcting brackets.
- Outputs the repaired JSON. In most cases, the result is ready to parse or use immediately.
- If the structure cannot be repaired automatically, a clear error is shown so you can adjust your input.
Common JSON Errors and How to Fix Them
Here are typical JSON mistakes that this tool can repair, with examples for each:
Unquoted Keys
Keys must be in double quotes.
{ name: "Bob" }
{ "name": "Bob" }
Fix: Adds double quotes around any unquoted object keys.
Single Quotes Used
JSON only accepts double quotes for strings.
{ 'role': 'admin' }
{ "role": "admin" }
Fix: Replaces single quotes with double quotes for all strings.
Trailing Commas
No comma is allowed after the last item.
{ "a": 1, "b": 2, }
{ "a": 1, "b": 2 }
Fix: Removes any trailing commas.
Mismatched or Unclosed Brackets
All brackets and braces must close properly.
[1, 2, 3
[1, 2, 3]
Fix: Adds missing closing brackets or braces.
Missing or Extra Commas
Array and object items must be separated by a single comma.
{ "a": 1 "b": 2 }
{ "a": 1, "b": 2 }
Fix: Inserts missing commas, or removes duplicates.
Comment Lines Present
Standard JSON does not allow comments (like // or /* ... */).
{ "id": 1, // user ID "active": true }
{ "id": 1, "active": true }
Fix: Removes comment lines from the input.
Invalid Number Formats
Only plain decimal numbers are valid (no NaN, Infinity, or hexadecimal).
{ "val": NaN }
{ "val": null }
Fix: Replaces invalid numbers with null.
Unescaped Control Characters
Characters like newlines in strings must be escaped.
{ "msg": "Line1 Line2" }
{ "msg": "Line1\nLine2" }
Fix: Escapes control characters correctly.
Duplicate Keys in Object
Duplicate keys in the same object cause ambiguity.
{ "name": "A", "name": "B" }
{ "name": "B" }
Fix: Keeps only the last value for any duplicate key.
Malformed Arrays
Arrays must have brackets and commas between items.
[ 1 2 3 ]
[ 1, 2, 3 ]
Fix: Adds missing commas between array elements.
Empty Input or All Whitespace
JSON cannot be empty.
null
Fix: Returns null for empty input.
Example: From Broken JSON to a Valid Repair
{ user: 'alice', id: 42, roles: [admin, 'editor',] // extra comma active: true }Repaired JSON Output
{ "user": "alice", "id": 42, "roles": [ "admin", "editor" ], "active": true }
How to Use This JSON Repair Tool
- Paste or type your broken JSON into the editor below.
- Click 'Repair' to automatically detect and fix common syntax errors.
- Review the repaired output and copy your fixed JSON.
Always check repaired JSON before using it for critical data—manual adjustments may be needed for complex or highly damaged inputs.
Code Examples for JSON Repair
See how to repair JSON in various programming languages.
const { jsonrepair } = require('jsonrepair');
const broken = '{ name: "Bob", age: 42, }';
const fixed = jsonrepair(broken);
console.log(fixed); // Now valid JSON!
let broken = "{ name: 'Bob', age: 42 }";
broken = broken.replace(/(['"])?:([\s]*)([^\s,\{\}\[\]":']+)/g, '"$1$3":');
try {
let obj = JSON.parse(broken);
console.log(obj);
} catch (e) {
console.error('Still broken:', e.message);
}
import dirtyjson
broken = "{ name: 'Bob', age: 42 }"
obj = dirtyjson.loads(broken)
print(obj)
import demjson3
broken = "{ name: 'Bob', age: 42 }"
obj = demjson3.decode(broken)
print(obj)
package main
import (
"fmt"
"github.com/robertkrimen/otto"
)
func main() {
vm := otto.New()
broken := "{ name: 'Bob', age: 42 }"
value, err := vm.Run("(" + broken + ")")
if err != nil {
fmt.Println("Cannot repair:", err)
} else {
obj, _ := value.Export()
fmt.Println(obj)
}
}
import org.json.JSONObject;
public class Main {
public static void main(String[] args) {
String broken = "{'name': 'Bob', 'age': 42}".replace(''', '"');
JSONObject obj = new JSONObject(broken);
System.out.println(obj);
}
}
using System;
using Newtonsoft.Json;
class Program {
static void Main() {
var broken = "{ name: 'Bob', age: 42 }".Replace("'", "\"");
try {
var obj = JsonConvert.DeserializeObject(broken);
Console.WriteLine(obj);
} catch (Exception ex) {
Console.WriteLine("Broken JSON: " + ex.Message);
}
}
}
<?php
$broken = "{ name: 'Bob', age: 42 }";
$fixed = preg_replace("/'([^"]*)'/", '"$1"', $broken);
$fixed = preg_replace('/([a-zA-Z0-9_]+):/', '"$1":', $fixed);
$obj = json_decode($fixed);
var_dump($obj);
# Using system call to npx jsonrepair
require 'open3'
broken = "{ name: 'Bob', age: 42 }"
fixed, _ = Open3.capture2("echo #{broken.inspect} | npx jsonrepair")
puts fixed
echo "{ name: 'Bob', age: 42 }" | npx jsonrepair
// Rust does not have a json repair crate yet. Pre-process string with regex to fix simple cases, then use serde_json.
import org.json.JSONObject
fun main() {
var broken = "{ name: 'Bob', age: 42 }".replace("'", "\"")
broken = Regex("([a-zA-Z0-9_]+):").replace(broken, ""$1":")
val obj = JSONObject(broken)
println(obj)
}
import { jsonrepair } from 'jsonrepair';
const broken = '{ name: "Bob", age: 42 }';
const fixed = jsonrepair(broken);
console.log(fixed);
var broken = "{ name: 'Bob', age: 42 }";
var fixed = broken.replaceAll("'", '"').replaceAllMapped(
RegExp(r'([a-zA-Z0-9_]+):'),
(m) => '"${m[ 1 ]}":',
);
print(fixed);
broken = "{ name: 'Bob', age: 42 }"
fixed = Regex.replace(~r/'/, broken, """)
fixed = Regex.replace(~r/(\w+):/, fixed, ""\\1":")
IO.puts(fixed)