Skip to main content

๐Ÿ› ๏ธ Process AI Output to Structured JSON with Robust JSON Parser

Workflow preview

Workflow preview
100%
๐Ÿ› ๏ธ Process AI Output to Structured JSON with Robust JSON Parser preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

How it works This workflow is a robust and forgiving JSON parser designed to handle malformed or "dirty" JSON strings often returned by AI models or scraped from web pages. It takes a text string a...

Best for

  • Engineering automation workflows
  • AI Summarization automation workflows
  • intermediate n8n builders looking for reusable templates

Tools used

n8n-nodes-base.executeworkflowtrigger, n8n-nodes-base.code, n8n-nodes-base.set, n8n-nodes-base.stickynote

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Lucas Peyrin.

Original n8n.io source

1.1 Workflow description

Title
๐Ÿ› ๏ธ Process AI Output to Structured JSON with Robust JSON Parser
Workflow name
๐Ÿ› ๏ธ Process AI Output to Structured JSON with Robust JSON Parser

How it works

This workflow is a robust and forgiving JSON parser designed to handle malformed or "dirty" JSON strings often returned by AI models or scraped from web pages. It takes a text string as input and attempts to extract and parse a valid JSON object from it.

  1. Cleans Input: It starts by trimming whitespace and removing common Markdown code fences (like ```json) that might wrap the JSON.
  2. Applies Multiple Fixes: It systematically attempts to correct common JSON errors in a specific order:
    • Escapes unescaped control characters (like newlines) within strings.
    • Fixes invalid backslash escape sequences.
    • Removes trailing commas.
    • Intelligently attempts to fix unescaped double quotes inside string values.
  3. Parses Strategically: If a direct parse fails, it tries to extract a potential JSON object from the text (e.g., finding a {...} block inside a larger sentence) and then re-applies the cleaning logic to that extracted portion.
  4. Outputs Clean Data: If successful, it outputs the parsed JSON fields. By default, it removes the detailed parsing_status object, but you can deactivate the final "Set" node to keep it for debugging.

Set up steps

Setup time: ~1 minute

This workflow is designed to be used as a sub-workflow and requires no internal setup.

  1. In your main workflow, add an Execute Sub-Workflow node where you need to parse a messy JSON string.
  2. In the Workflow parameter, select this "Robust JSON Parser" workflow.
  3. Ensure the data you send to the node is a JSON object containing a text field, where the value of text is the string you want to parse. For example: { "text": "{\\\"key\\\": \\\"some broken json...\\\"}" }.
  4. The workflow will return the successfully parsed data. To see a detailed log of the cleaning process, simply deactivate the final Remove parsing_status node inside this workflow.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Robust JSON Parser

Type / Role
n8n-nodes-base.executeWorkflowTrigger - executeWorkflowTrigger
Config choices
Version 1.1

Block 2 - Safe JSON Parser

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 3 - Remove parsing_status

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 4 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 5 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 6 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 7 - Convert to JSON

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 8 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 9 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

3. Summary Table

Workflow ๐Ÿ› ๏ธ Process AI Output to Structured JSON with Robust JSON Parser
Complexity intermediate
Nodes 9
Categories Engineering, AI Summarization
Author Lucas Peyrin
Published 23 Jun 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/5146/5146.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does ๐Ÿ› ๏ธ Process AI Output to Structured JSON with Robust JSON Parser do?

How it works This workflow is a robust and forgiving JSON parser designed to handle malformed or "dirty" JSON strings often returned by AI models or scraped from web pages. It takes a text string a...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Engineering, AI Summarization use case.