Skip to main content

Cleans up truncated json files.

Project description

# untruncate_json Python library to repair truncated json. Translated directly from the typescript original version

## Installation

`bash pip install untruncate_json ` ## Usage

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.

`python import untruncate_json assert untruncate_json.complete('{"foo": "bar') == '{"foo": "bar"}' `

## Goals My goal is for the library to be a pure python library that handles as many cases as the other libraries.

## Credits 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.

## Prior Art

## Benchmarks

  • truncjson: 1.28

  • untruncate_json: 11.39

  • untruncate_json: 1.14 (if you run mypyc untruncate_json

  • jsonfixer: 23.06

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

untruncate_json-1.0.0.tar.gz (9.9 kB view hashes)

Uploaded Source

Built Distributions

untruncate_json-1.0.0-cp312-cp312-win_amd64.whl (60.6 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

untruncate_json-1.0.0-cp312-cp312-musllinux_1_1_x86_64.whl (95.3 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

untruncate_json-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (93.3 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

untruncate_json-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (72.7 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

untruncate_json-1.0.0-cp312-cp312-macosx_10_9_x86_64.whl (73.8 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

untruncate_json-1.0.0-cp311-cp311-win_amd64.whl (60.6 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

untruncate_json-1.0.0-cp311-cp311-musllinux_1_1_x86_64.whl (95.2 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

untruncate_json-1.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (93.5 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

untruncate_json-1.0.0-cp311-cp311-macosx_11_0_arm64.whl (72.9 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

untruncate_json-1.0.0-cp311-cp311-macosx_10_9_x86_64.whl (72.9 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

untruncate_json-1.0.0-cp310-cp310-win_amd64.whl (60.9 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

untruncate_json-1.0.0-cp310-cp310-musllinux_1_1_x86_64.whl (96.7 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

untruncate_json-1.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (94.7 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

untruncate_json-1.0.0-cp310-cp310-macosx_11_0_arm64.whl (74.2 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

untruncate_json-1.0.0-cp310-cp310-macosx_10_9_x86_64.whl (74.2 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

untruncate_json-1.0.0-cp39-cp39-win_amd64.whl (60.8 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

untruncate_json-1.0.0-cp39-cp39-musllinux_1_1_x86_64.whl (96.6 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

untruncate_json-1.0.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (94.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

untruncate_json-1.0.0-cp39-cp39-macosx_11_0_arm64.whl (74.2 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

untruncate_json-1.0.0-cp39-cp39-macosx_10_9_x86_64.whl (74.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

untruncate_json-1.0.0-cp38-cp38-win_amd64.whl (60.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

untruncate_json-1.0.0-cp38-cp38-musllinux_1_1_x86_64.whl (95.5 kB view hashes)

Uploaded CPython 3.8 musllinux: musl 1.1+ x86-64

untruncate_json-1.0.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (94.4 kB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

untruncate_json-1.0.0-cp38-cp38-macosx_11_0_arm64.whl (73.3 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

untruncate_json-1.0.0-cp38-cp38-macosx_10_9_x86_64.whl (73.4 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page