json_repair is a Python library that repairs malformed JSON from language models, APIs, logs, and user input.
The tool addresses the common problem of improperly formatted JSON output, particularly from large language models that may omit quotation marks, commas, brackets, or include stray text. It works by parsing broken JSON and reconstructing valid output, fixing syntax errors such as missing quotes, misplaced commas, unescaped characters, and incomplete key-value pairs. The library handles Python-style tuples by converting them to JSON arrays, recognizes boolean and null values case-insensitively, and auto-completes missing fields with reasonable defaults like empty strings or null values. It can also strip out comments and extraneous non-JSON characters while preserving the intended data structure.
Developers should adopt this tool if they work with JSON output from language models or other unreliable sources where standard parsing fails. It works as a drop-in replacement for json.loads() or as a schema-guided repair step, making it suitable for pipelines that need to handle imperfect JSON without manual intervention. The library is lightweight and designed specifically for the kinds of mistakes that language models typically make, rather than attempting to handle arbitrary malformed JSON.
The project shows active maintenance with responsiveness to issues and pull requests. Development includes regular updates to handle new edge cases and improvements to the repair logic. The maintainer has documented the tool thoroughly with a live demo and audio overview available for users to test their specific use cases before adoption.