This n8n workflow is designed to intelligently parse and clean potentially malformed JSON strings, making it highly useful for processing data embedded in text inputs, logs, or external sources. The goal of the workflow is to extract valid JSON even from poorly formatted or corrupted strings, ensuring reliable data handling.
The process begins with an input node, where a string containing JSON is provided. The main logic resides in a sophisticated parser node that performs multiple steps to clean and fix common JSON issues:
– It detects and removes markdown fences and trims whitespace.
– It escapes control characters within JSON strings, such as newlines, tabs, and carriage returns.
– It corrects invalid escape sequences by properly escaping backslashes.
– It removes trailing commas that invalidate JSON.
– It attempts to fix unescaped quotes within JSON strings.
The parser then tries to parse the cleaned string. If parsing fails, it extracts potential JSON candidates based on bracket balancing and applies similar fixes to each candidate. Each step logs its actions for debugging purposes.
Finally, the workflow outputs either the successfully parsed JSON object or array, or, if all attempts fail, it provides a detailed parsing status. Additional nodes allow you to remove the debugging info for cleaner outputs.
This workflow is useful for situations where JSON data is received from external APIs, malformed logs, or user inputs, and ensures that data can be reliably parsed regardless of formatting issues.
Reviews
There are no reviews yet.