// n8n integration

AI JSON Parser (Clean & Repair)

This operation is available on both n8n Cloud and self-hosted n8n and requires the CustomJS community package. It ships with the next release of the @custom-js/n8n-nodes-pdf-toolkit-v2 package, available from version 0.12.0. See Installation.

The AI JSON Parser operation turns messy AI model output into clean, structured JSON. It fixes exactly the cases where n8n's built-in JSON parsing throws an error:

  • Markdown code fences around the JSON, as produced by the AI Agent, OpenAI, and Anthropic nodes
  • Prose around the JSON, e.g. "Here is the result you asked for: { ... } Let me know if you need anything else."
  • Python literals like True, False, and None instead of true, false, and null
  • Double-encoded strings, where the JSON was serialized twice and arrives as one long escaped string
  • Smart quotes and trailing commas that break JSON.parse

Instead of writing a fragile Code node with regex cleanup, add this operation between your AI node and the rest of your workflow. You can find the same cleanup patterns for other platforms in our data cleanup snippets.

Where to find it

The operation lives in the CustomJS (PDF & File Toolkit) node:

  1. Add the PDF Toolkit node to your workflow
  2. Set Resource to Data
  3. Set Operation to AI JSON Parser

Configuration

Node Parameters

ParameterDescriptionRequired
JSON TextRaw text that should contain JSON, e.g. an AI model answerYes
Strict ModeStrict mode: no content repairs. Only fence removal and block extraction are applied, the content itself is never modifiedNo (default: off)

Example

Input (typical AI Agent output):

Sure! Here is the extracted data:

```json
{
  "name": "John Doe",
  "active": True,
  "score": 87.5,
}
```

Let me know if you need anything else.

Output:

{
  "result": {
    "name": "John Doe",
    "active": true,
    "score": 87.5
  },
  "wasRepaired": true,
  "notes": [
    "Removed markdown code fences",
    "Extracted JSON block from surrounding text",
    "Repaired common issues (smart quotes, trailing commas, Python/JS literals)"
  ]
}

Output Fields

FieldDescription
resultThe parsed JSON value, ready to use in downstream nodes
wasRepairedtrue if any cleanup or repair was applied, false if the input parsed as-is
notesA list of the cleanup steps that were applied, useful for debugging

If the text cannot be parsed even after cleanup, the node throws a clear error so you can catch it with n8n's error handling.