Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

untruncate-json

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

untruncate-json

Cleans up truncated json files.

  • 1.0.0
  • PyPI
  • Socket score

Maintainers
1

untruncate_json

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

Installation

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.

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

  • untruncate-json - Original Typescript version
  • truncjson Cython implementation
  • jsonfixer Fork of half-json?
  • half-json

Benchmarks

  • truncjson: 1.28
  • untruncate_json: 11.39
  • untruncate_json: 1.14 (if you run mypyc untruncate_json
  • jsonfixer: 23.06

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc