Skip to content

[Feature Request]: Add timeout parameter to repair_json #203

Closed

Description

@MaKaili

Describe the solution you'd like

Thanks for maintaining this project!

I’d like to request a simple feature: add an optional timeout parameter to the repair_json function.

In some cases, when the input JSON string is badly malformed, the repair process may take too long. A timeout option would allow users to stop the repair process after a specified amount of time. The feature is friendly for Python users to stop a repair task that may take a very long time.

Example usage:

from json_repair import repair_json

result = repair_json(bad_json, timeout=5)

Expected behavior:

  • timeout is optional.
  • If not provided, the current behavior stays unchanged.
  • If the timeout is reached, the function should raise an exception or return a clear error.

Thank you so much!

Context

I ran into a problematic case with a malformed JSON response that contained an unclosed string followed by many comma-separated fragments. For this input shape, the runtime appeared to grow non-linearly as the input size increased:

~5.9 KB   -> 0.88s
~17.6 KB  -> 8.34s
~35 KB    -> exceeded a 20s timeout

In production or user-facing applications, this kind of input can cause a request to hang for too long. An optional timeout parameter would let callers put an upper bound on repair time, fail gracefully, and avoid blocking the application when malformed input triggers very slow repair behavior.

Activity

  1. mangiucugna commented on Jun 29, 2026

    @mangiucugna
    Owner

    Hi, thanks for reporting. Before I add a feature like this that would require some work, can you try the latest release? I have investigated your report and I think I found the performance bottlenecks that require a timeout to begin with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions