Skip to main content

ensure-json

Repair and parse "almost-JSON" from LLMs (like GPT, Claude) into valid Python objects, or raise a clear error. Works in any Python 3.7+ environment. Zero dependencies (Pydantic optional for schema validation).


Install

pip install ensure-json

Usage

As a Python Library

from ensure_json import ensure_json, JsonFixError

try:
    obj = ensure_json('{ name: "Alice", age: 42, }')
    print(obj)  # {'name': 'Alice', 'age': 42}
except JsonFixError as err:
    print("Could not parse JSON:", err)

With Pydantic Schema (optional)

from ensure_json import ensure_json
from pydantic import BaseModel

class User(BaseModel):
    name: str
    age: int

user = ensure_json('{ name: "Alice", age: 42 }', schema=User)
print(user)  # User(name='Alice', age=42)

Command Line

echo '{ name: "Alice", age: 42, }' | ensure-json
# or
echo '{ name: "Alice", age: 42, }' | python -m ensure_py.cli

Features

  • Repairs and parses "almost-JSON" from LLMs (extra commas, unquoted keys, etc.)
  • Returns a valid Python object or raises JsonFixError
  • Optional Pydantic schema validation
  • Minimal CLI for quick fixes
  • No dependencies required (Pydantic optional)

License

MIT

Metadata

Release files for ensure-json 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ensure-json 0.1.1
File Size Uploaded Provenance Actions
ensure_json-0.1.1.tar.gz 3.1 kB Without provenance Details for ensure_json-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ensure-json 0.1.1
File Interpreter ABI Platform Actions
ensure_json-0.1.1-py3-none-any.whl Python 3 none any Details for ensure_json-0.1.1-py3-none-any.whl

Total release size: 6.6 kB

Release files / ensure_json-0.1.1.tar.gz

Download URL ensure_json-0.1.1.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9af7561db77877ef7567971dcf34495c77275e659f06ac94a2f70c4a680700ff
BLAKE2b-256 checksum
How to use checksums
5e36cb5f3ca306dadc8df50074e9dcb2e642b582fcae96165c47c57f43365236
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / ensure_json-0.1.1-py3-none-any.whl

Download URL ensure_json-0.1.1-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c8caa34d7da4f4b35094f841a6c443f74650f8203d5ac274ac57989d3c2f0f43
BLAKE2b-256 checksum
How to use checksums
2499ffcac2f6ea7b2f561238194335fb2bd44a16f559e1eccfaa287989f65bb1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Security for ensure-json 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page