Skip to content

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

  1. Find the JSON boundaries – The component looks for the first { and the last } to isolate the JSON part of the input.
  2. 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.
  3. Repair the JSON – Uses the json_repair library to fix any remaining syntax errors.
  4. 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

  1. Get a messy JSON string – For example, an LLM returns:
    {name: "Alice", age: 30, bio: "Loves coding\x07"}
  2. Add the JSON Cleaner component – Drag it onto the canvas and connect the LLM’s output to the JSON String input.
  3. 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.
  4. Run the workflow – The component outputs a clean JSON string:
    {"name":"Alice","age":30,"bio":"Loves coding"}
  5. Use the cleaned JSON – Connect the output to a JSON Parser, a database writer, or any other component that requires valid JSON.
  • 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.