πŸ”§JSON Repair Block

Repair and fix invalid JSON documents

Automatically repair and fix invalid JSON using the jsonrepair library. This block can handle various JSON formatting issues and convert them into valid JSON.

You may be generating JSON from an unreliable source like an LLM or an external API, which might output invalid or poorly formatted JSON. Adding this block to your workflow ensures you end up with valid JSON. If the block can't repair your input then it will throw an error.

Input JSON

Paste or type your input into the "JSONish string" input, or use a variable from another block.

Features

The JSON Repair block uses the jsonrepair library to fix the following issues:

  • Add missing quotes around keys

  • Add missing escape characters

  • Add missing commas

  • Add missing closing brackets

  • Repair truncated JSON

  • Replace single quotes with double quotes

  • Replace special quote characters like "..." with regular double quotes

  • Replace special white space characters with regular spaces

  • Replace Python constants None, True, and False with null, true, and false

  • Strip trailing commas

  • Strip comments like /* ... */ and // ...

  • Strip ellipsis in arrays and objects like [1, 2, 3, ...]

  • Strip JSONP notation like callback({ ... })

  • Strip escape characters from an escaped string like {\"stringified\": \"content\"}

  • Strip MongoDB data types like NumberLong(2) and ISODate("2012-12-19T06:01:17.171Z")

  • Concatenate strings like "long text" + "more text on next line"

  • Turn newline delimited JSON into a valid JSON array

Output

The block will output the repaired JSON.

Example

Input (invalid JSON):

{
  name: 'John',
  age: 30,
  active: True,
  tags: ['dev', 'ops', ...],
  // This is a comment
  description: "long text" + "more text"
}

Output (valid JSON):

{
  "name": "John",
  "age": 30,
  "active": true,
  "tags": ["dev", "ops"],
  "description": "long textmore text"
}

Last updated