Partial JSON Parser

1.1.0 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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': []}

view raw JSON →