JSON Cleaner
JSON Cleaner is a tool that takes a JSON string that might be broken or messy—often produced by language models—and turns it into a clean, well‑formed JSON string that can be used safely in other parts of your workflow.
How it Works
- Find the JSON boundaries – The component looks for the first
{
and the last}
to isolate the JSON part of the input. - Optional cleaning steps –
- Remove Control Characters – Deletes hidden characters that can break JSON.
- Normalize Unicode – Converts Unicode characters to a standard form so they display correctly.
- Validate JSON – Checks that the string is already valid JSON before repairing.
- Repair the JSON – Uses the
json_repair
library to fix any remaining syntax errors. - Return the result – The cleaned JSON string is returned as a
Message
that can be passed to other components.
The entire process happens locally on your machine; no external API calls are made.
Inputs
- JSON String: The JSON string you want to clean. This field is required.
- Normalize Unicode: If checked, the component will convert Unicode characters to a standard form.
- Remove Control Characters: If checked, the component will delete hidden control characters that can break JSON.
- Validate JSON: If checked, the component will first verify that the string is already valid JSON before attempting to repair it.
Outputs
- Cleaned JSON String: The resulting, well‑formed JSON string is returned as a
Message
. You can feed this output into other components that expect valid JSON.
Usage Example
- Get a messy JSON string – For example, an LLM returns:
{name: "Alice", age: 30, bio: "Loves coding\x07"}
- Add the JSON Cleaner component – Drag it onto the canvas and connect the LLM’s output to the JSON String input.
- Configure options –
- Check Remove Control Characters to delete the stray
\x07
. - Check Validate JSON if you want to ensure the string is already correct before repairing.
- Check Remove Control Characters to delete the stray
- Run the workflow – The component outputs a clean JSON string:
{"name":"Alice","age":30,"bio":"Loves coding"}
- Use the cleaned JSON – Connect the output to a JSON Parser, a database writer, or any other component that requires valid JSON.
Related Components
- JSON Parser – Parses a clean JSON string into a data structure you can work with.
- Data Formatter – Formats JSON or other data for display or export.
- LLM Output – Generates raw text that may contain JSON; often paired with JSON Cleaner.
Tips and Best Practices
- Keep the input concise – The cleaner works best when the JSON is close to valid; large, heavily corrupted strings may still need manual review.
- Use Validate JSON sparingly – Validation adds a small overhead; enable it only if you’re confident the string is mostly correct.
- Check the output – Even after cleaning, review the JSON to ensure it contains the data you expect.
- Combine with other components – After cleaning, feed the JSON into a parser or a database writer for further processing.
Security Considerations
- The component processes data locally; no external services are called.
- If your JSON contains sensitive information, treat the output with the same security precautions as any other data in your workflow.
- Avoid exposing the cleaned JSON in public dashboards unless you’re sure it’s safe to share.