Python library to repair truncated json. Translated directly from the typescript original version
pip install untruncate_json
In some cases, a partial json document is invalid and there is no way to recover. A common scenario using OpenAI's chatbot is that the AI created json is truncated at the end of the document. This library will attempt to repair the json by adding the missing closing brackets.
If the context of the json is relatively simple and holds natural language, truncating the text might not degrade the final result much.
import untruncate_json
assert untruncate_json.complete('{"foo": "bar') == '{"foo": "bar"}'
My goal is for the library to be a pure python library that handles as many cases as the other libraries.
Original Typescript version by dphilipson, MIT license. Code translated by a lazy ChatGPT that didn't want to translate the long switch blocks. Copilot translated the switch blocks.
- untruncate-json - Original Typescript version
- truncjson Cython implementation
- jsonfixer Fork of half-json?
- half-json
- truncjson: 1.28
- untruncate_json: 11.39
- untruncate_json: 1.14 (if you run
mypyc untruncate_json
- jsonfixer: 23.06