{"id":6692,"library":"jsonslicer","title":"JsonSlicer","description":"JsonSlicer is a Python library (version 0.1.8) designed for efficient stream or iterative JSON parsing. It processes JSON documents without loading the entire structure into memory, making it suitable for very large files or streams. Written in C and leveraging the YAJL JSON parsing library, it offers high performance. JsonSlicer provides an iterator interface to extract specific data by defining paths using map keys and array indices, yielding matching JSON data as complete Python objects. Its release cadence is irregular, with minor updates addressing compatibility and performance.","status":"active","version":"0.1.8","language":"en","source_language":"en","source_url":"https://github.com/AMDmi3/jsonslicer","tags":["json","parsing","streaming","performance","yajl","iterator"],"install":[{"cmd":"pip install jsonslicer","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core C library dependency for JSON parsing. Version 2.0.3+ required.","package":"yajl","optional":false},{"reason":"Build-time dependency for locating YAJL.","package":"pkg-config","optional":false},{"reason":"Build-time dependency as the core module is written in C.","package":"C++ compiler","optional":false}],"imports":[{"symbol":"JsonSlicer","correct":"from jsonslicer import JsonSlicer"}],"quickstart":{"code":"import os\nimport json\nfrom jsonslicer import JsonSlicer\n\n# Create a dummy JSON file for demonstration\ndata = {\n    \"friends\": [\n        {\"name\": \"John\", \"age\": 31},\n        {\"name\": \"Ivan\", \"age\": 26}\n    ],\n    \"colleagues\": {\n        \"manager\": {\"name\": \"Jack\", \"age\": 33},\n        \"subordinate\": {\"name\": \"Lucy\", \"age\": 21}\n    }\n}\nwith open('people.json', 'w') as f:\n    json.dump(data, f)\n\n# Extract a specific element\nwith open('people.json') as data_file:\n    ivans_age = next(JsonSlicer(data_file, ('friends', 1, 'age')))\n    print(f\"Ivan's age: {ivans_age}\") # Expected: Ivan's age: 26\n\n# Iterate over a collection using wildcards (None)\nwith open('people.json') as data_file:\n    print(\"\\nFriends:\")\n    for person in JsonSlicer(data_file, ('friends', None)):\n        print(person) # Expected: {'name': 'John', 'age': 31}, {'name': 'Ivan', 'age': 26}\n\n# Iterate over different types of collections at once\nwith open('people.json') as data_file:\n    print(\"\\nAll people:\")\n    for person in JsonSlicer(data_file, (None, None)):\n        print(person) # Expected: all 4 people objects\n\n# Clean up the dummy file\nos.remove('people.json')","lang":"python","description":"This quickstart demonstrates how to extract specific values and iterate over collections within a JSON file using `JsonSlicer`. It shows direct path extraction and the use of `None` as a wildcard for iterating through arrays or dictionary values."},"warnings":[{"fix":"Ensure C++ development tools (e.g., `build-essential` on Debian/Ubuntu, Xcode Command Line Tools on macOS) and `pkg-config` are installed before attempting to `pip install jsonslicer`.","message":"Installation requires a C++ compiler and `pkg-config` to build the YAJL dependency, which might fail on systems without proper development tools.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When reading from a file, open it in binary read mode: `with open('file.json', 'rb') as data: JsonSlicer(data, ...)`.","message":"For optimal performance, especially with very large JSON files, `JsonSlicer` prefers binary input. Using text input (e.g., a file opened without `rb` mode) incurs a ~3% performance overhead due to unnecessary encoding/decoding.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Benchmark against `ijson` (with `yajl2_c` backend if available) for specific deep parsing scenarios to determine the optimal library. Consider the complexity of the extraction path vs. the volume of data to be converted to Python objects.","message":"While generally faster than pure Python JSON parsers, `jsonslicer` can sometimes be slower than `ijson` with its C backend for very deep data structures if many intermediate C values need to be converted to Python objects.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to `jsonslicer` version 0.1.5 or newer: `pip install --upgrade jsonslicer`.","message":"Versions prior to 0.1.5 might have compatibility issues with Python 3.8 and newer due to a compatibility fix introduced in that release.","severity":"deprecated","affected_versions":"<0.1.5"},{"fix":"When initializing `JsonSlicer`, pass `yajl_verbose_errors=True` to get detailed error messages including the JSON text and character where the error occurred. E.g., `JsonSlicer(data_file, path, yajl_verbose_errors=True)`.","message":"The `yajl_verbose_errors` flag can be set to enable more detailed error messages, which might be helpful for debugging malformed JSON, as the default error verbosity might be limited.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}