{"id":7491,"library":"partialjson","title":"Partial JSON Parser","description":"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.","status":"active","version":"1.1.0","language":"en","source_language":"en","source_url":"https://github.com/iw4p/partialjson","tags":["json","parsing","incomplete-data","data-processing"],"install":[{"cmd":"pip install partialjson","lang":"bash","label":"Install `partialjson`"}],"dependencies":[],"imports":[{"symbol":"loads","correct":"from partialjson import loads"},{"note":"For loading from file-like objects.","symbol":"load","correct":"from partialjson import load"},{"note":"A custom JSON encoder, similar to `json.dumps`.","symbol":"dumps","correct":"from partialjson import dumps"}],"quickstart":{"code":"from partialjson import loads\n\n# Example 1: Incomplete dictionary\nincomplete_json_dict = '{\"name\": \"Alice\", \"age\": 30, \"isStudent\": tru'\ndata_dict = loads(incomplete_json_dict)\nprint(f\"Parsed dict: {data_dict}\")\n# Expected: {'name': 'Alice', 'age': 30}\n\n# Example 2: Incomplete list\nincomplete_json_list = '[1, 2, {\"item\": \"value\"'\ndata_list = loads(incomplete_json_list)\nprint(f\"Parsed list: {data_list}\")\n# Expected: [1, 2]\n\n# Example 3: Deeply incomplete\ndeep_incomplete = '{\"user\": {\"id\": 123, \"name\": \"Bob\"}, \"products\": [{\"id\": 1' \nparsed_deep = loads(deep_incomplete)\nprint(f\"Parsed deep: {parsed_deep}\")\n# Expected: {'user': {'id': 123, 'name': 'Bob'}, 'products': []}","lang":"python","description":"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."},"warnings":[{"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.","message":"The `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).","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure the input string is intended to be JSON and check for severe malformations beyond simple incompleteness (e.g., incorrect syntax within an already established JSON object/array). `partialjson` fixes *trailing* incompleteness, not internal syntax errors.","cause":"This error indicates that `partialjson` encountered an unrecoverable JSON syntax error or non-JSON input that it couldn't even partially parse. It often means the input is more than just incomplete; it's fundamentally malformed.","error":"json.decoder.JSONDecodeError: Expecting value: line X column Y (char Z)"},{"fix":"Install the library using pip: `pip install partialjson`","cause":"The `partialjson` library is not installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'partialjson'"},{"fix":"Ensure the argument passed to `partialjson.loads()` is a string (or bytes/path-like object) representing the JSON data.","cause":"`partialjson.loads()` expects a string, bytes, or path-like object as its input, but received an incompatible type (e.g., an integer, list, or dictionary).","error":"TypeError: expected string, bytes or os.PathLike object, not X"}]}