Skip to main content

json_partial_py is a resilient JSON parsing library written in Rust that goes beyond the strict JSON specification. It’s designed to parse not only valid JSON but also "JSON‐like" input that may include common syntax errors, multiple JSON objects, or JSON embedded in markdown code blocks.

This is python bindings for json_partial library (Rust).

Usage:

pip install json_partial_python

Simple Example

 
from pydantic import BaseModel
from json_partial_py import to_json_string

# Define a simple Pydantic model that matches the expected JSON structure.
class Person(BaseModel):
    name: str
    age: int

# Example input: A malformed JSON wrapped in Markdown fences.
MALFORMED_JSON = r"""
```json
{"name": "Bob", "age": 25}
```
"""

json_str = to_json_string(MALFORMED_JSON)
person = Person.model_validate_json(json_str)
print(person)

Advanced Example

 
from typing import List
from pydantic import BaseModel
from json_partial_py import to_json_string

# Define nested models for the JSON structure.
class Coordinates(BaseModel):
    lat: float
    lng: float

class Address(BaseModel):
    street: str
    city: str
    country: str
    coordinates: Coordinates

class Hobby(BaseModel):
    name: str
    years_active: int
    proficiency: str

class Person(BaseModel):
    name: str
    age: int
    address: Address
    hobbies: List[Hobby]

# Example input: A complex nested JSON wrapped in Markdown fences.
MALFORMED_NESTED_JSON = r"""
```json
{
    "name": "Bob",
    "age": 42,
    "address": {
        "street": "789 Pine Rd",
        "city": "Metropolis",
        "country": "USA",
        "coordinates": {"lat": 40.7128, "lng": -74.0060}
    },
    "hobbies": [
        {"name": "Cooking", "years_active": 5, "proficiency": "intermediate"},
        {"name": "Cycling", "years_active": 10, "proficiency": "expert"}
    ]
}
```
"""

json_str = to_json_string(MALFORMED_NESTED_JSON)
person = Person.model_validate_json(json_str)
print(person)

One more corner case handled

MALFORMED_JSON=r"""
{ rec_one: "and then i said \"hi\", and also \"bye\"", rec_two: "and then i said "hi", and also "bye"", "also_rec_one": ok }
"""

json_str = to_json_string(MALFORMED_NESTED_JSON)
print(json.loads(json_str))

Publishing

To compile to the desired target using Zig, execute the following command: maturin build --release --target aarch64-unknown-linux-gnu --zig maturin build --release --target x86_64-unknown-linux-gnu --zig

After building, move the files from the target/wheels directory to the dist/ folder using the following command:

cp target/wheels/* dist/

Finally, use the command uv publish to publish the package.

Metadata

Release files for json_partial_python 0.1.3

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

Built distribution (wheel)

Table of built distributions (wheels) for json_partial_python 0.1.3
File Interpreter ABI Platform Actions
json_partial_python-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for json_partial_python-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Release files / json_partial_python-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL json_partial_python-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 937.9 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
59f1c9145dd4876c1e0a4cdf488f785c75311d265141df15e256b62058e96fd6
BLAKE2b-256 checksum
How to use checksums
e60442d132effb494738fb516113b9026e8d6315790d37a35dddf27f4d78d209
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.5

Security for json_partial_python 0.1.3

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.

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