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.

  1. Parses the input and locates common syntax errors, including illegal characters, misplaced brackets, and incorrect string quotes.
  2. Applies fixes for frequent mistakes—like adding missing quotes, removing trailing commas, or correcting brackets.
  3. Outputs the repaired JSON. In most cases, the result is ready to parse or use immediately.
  4. 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.

Before:
{ name: "Bob" }
After:
{ "name": "Bob" }

Fix: Adds double quotes around any unquoted object keys.

Single Quotes Used

JSON only accepts double quotes for strings.

Before:
{ 'role': 'admin' }
After:
{ "role": "admin" }

Fix: Replaces single quotes with double quotes for all strings.

Trailing Commas

No comma is allowed after the last item.

Before:
{ "a": 1, "b": 2, }
After:
{ "a": 1, "b": 2 }

Fix: Removes any trailing commas.

Mismatched or Unclosed Brackets

All brackets and braces must close properly.

Before:
[1, 2, 3
After:
[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.

Before:
{ "a": 1 "b": 2 }
After:
{ "a": 1, "b": 2 }

Fix: Inserts missing commas, or removes duplicates.

Comment Lines Present

Standard JSON does not allow comments (like // or /* ... */).

Before:
{ "id": 1, // user ID
 "active": true }
After:
{ "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).

Before:
{ "val": NaN }
After:
{ "val": null }

Fix: Replaces invalid numbers with null.

Unescaped Control Characters

Characters like newlines in strings must be escaped.

Before:
{ "msg": "Line1
Line2" }
After:
{ "msg": "Line1\nLine2" }

Fix: Escapes control characters correctly.

Duplicate Keys in Object

Duplicate keys in the same object cause ambiguity.

Before:
{ "name": "A", "name": "B" }
After:
{ "name": "B" }

Fix: Keeps only the last value for any duplicate key.

Malformed Arrays

Arrays must have brackets and commas between items.

Before:
[ 1 2 3 ]
After:
[ 1, 2, 3 ]

Fix: Adds missing commas between array elements.

Empty Input or All Whitespace

JSON cannot be empty.

Before:
After:
null

Fix: Returns null for empty input.

Example: From Broken JSON to a Valid Repair

Malformed JSON Input
{ 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

  1. Paste or type your broken JSON into the editor below.
  2. Click 'Repair' to automatically detect and fix common syntax errors.
  3. 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.

JavaScript (Node.js) with jsonrepair
Install: npm install jsonrepair
const { jsonrepair } = require('jsonrepair');
const broken = '{ name: "Bob", age: 42, }';
const fixed = jsonrepair(broken);
console.log(fixed); // Now valid JSON!
JavaScript (Node.js) simple fix (not for production)
Install: Standard library
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);
}
Python with dirtyjson
Install: pip install dirtyjson
import dirtyjson
broken = "{ name: 'Bob', age: 42 }"
obj = dirtyjson.loads(broken)
print(obj)
Python with demjson3
Install: pip install demjson3
import demjson3
broken = "{ name: 'Bob', age: 42 }"
obj = demjson3.decode(broken)
print(obj)
Go (using otto for JS-like object parsing)
Install: go get github.com/robertkrimen/otto
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)
  }
}
Java with org.json (manual fix for single quotes)
Install: org.json:json
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);
  }
}
C# with Newtonsoft.Json (try-catch, manual fix)
Install: Newtonsoft.Json
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 (manual fix for single quotes/unquoted keys)
Install: Standard library
<?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);
Ruby with json-repair (via gem or shell call)
Install: gem install json-repair or use npx jsonrepair
# Using system call to npx jsonrepair
require 'open3'
broken = "{ name: 'Bob', age: 42 }"
fixed, _ = Open3.capture2("echo #{broken.inspect} | npx jsonrepair")
puts fixed
Bash (npx jsonrepair CLI)
Install: npm install -g jsonrepair
echo "{ name: 'Bob', age: 42 }" | npx jsonrepair
Rust (suggest manual pre-processing)
Install: Standard libraries
// Rust does not have a json repair crate yet. Pre-process string with regex to fix simple cases, then use serde_json.
Kotlin (manual fix, like Java)
Install: org.json: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)
}
TypeScript (Node.js) with jsonrepair
Install: npm install jsonrepair
import { jsonrepair } from 'jsonrepair';
const broken = '{ name: "Bob", age: 42 }';
const fixed = jsonrepair(broken);
console.log(fixed);
Dart (manual string fixes)
Install: Standard library
var broken = "{ name: 'Bob', age: 42 }";
var fixed = broken.replaceAll("'", '"').replaceAllMapped(
  RegExp(r'([a-zA-Z0-9_]+):'),
  (m) => '"${m[ 1 ]}":',
);
print(fixed);
Elixir (manual fix with Regex)
Install: Standard library
broken = "{ name: 'Bob', age: 42 }"
fixed = Regex.replace(~r/'/, broken, """)
fixed = Regex.replace(~r/(\w+):/, fixed, ""\\1":")
IO.puts(fixed)