Registry / serialization / partialjson

partialjson

JSON →
library1.1.0pypypi✓ verified 82d ago

The `partialjson` library provides a robust solution for parsing incomplete or partial JSON data in Python. It handles scenarios where JSON strings might be truncated or malformed at the end, returning the largest valid JSON object or array it can parse. The current version is 1.1.0, and releases appear to be infrequent, focusing on stability and bug fixes.

pip install partialjson
INSTALL
IMPORT
SIG · PARTIALJSON
P
partialjson
serializationpythonv1.1.0
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

JSONParser
from partialjson import JSONParser
from partialjson import loads
create_json_parser
from partialjson import create_json_parser
from partialjson import loads
create_json5_parser
from partialjson import create_json5_parser
from partialjson import loads

This quickstart demonstrates how to use `partialjson.loads()` to parse various forms of incomplete JSON strings, including dictionaries and lists. It shows how the library extracts the largest valid JSON structure possible from the truncated input.

from partialjson import loads # Example 1: Incomplete dictionary incomplete_json_dict = '{"name": "Alice", "age": 30, "isStudent": tru' data_dict = loads(incomplete_json_dict) print(f"Parsed dict: {data_dict}") # Expected: {'name': 'Alice', 'age': 30} # Example 2: Incomplete list incomplete_json_list = '[1, 2, {"item": "value"' data_list = loads(incomplete_json_list) print(f"Parsed list: {data_list}") # Expected: [1, 2] # Example 3: Deeply incomplete deep_incomplete = '{"user": {"id": 123, "name": "Bob"}, "products": [{"id": 1' parsed_deep = loads(deep_incomplete) print(f"Parsed deep: {parsed_deep}") # Expected: {'user': {'id': 123, 'name': 'Bob'}, 'products': []}
Debug
Known issues
gotchaThe `partialjson` library is specifically designed to handle *incomplete* or *truncated* JSON strings, typically at the end of the input. It does not attempt to correct arbitrary syntax errors or malformed structures that occur internally within an otherwise complete JSON segment (e.g., missing commas, incorrect data types within values).
fix
Ensure the input is conceptually an incomplete JSON string, not a fundamentally malformed one. For general JSON validation or error correction beyond simple truncation, consider other tools or pre-processing.
affects: All versions
gotchaWhen a value within a key-value pair (e.g., a string or number) is itself incomplete and cannot be fully parsed, the entire key-value pair might be omitted from the resulting parsed object to maintain JSON validity. For example, `{'key': "partial_stri` might result in `{}`, not `{'key': None}` or similar.
fix
Understand that the output is the largest *valid* JSON structure prefix. If a key's value is too incomplete to determine its type and complete it, the key-value pair might be dropped entirely.
affects: All versions
Upgrade
Version history
1.1.0latest on PyPI · released Feb 19, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources
partialjson — pip install partialjson · libregistry