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.
pip install jsonslicerVerified import paths — ran on the pinned version, not inferred.
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.
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`.
When reading from a file, open it in binary read mode: `with open('file.json', 'rb') as data: JsonSlicer(data, ...)`.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.
Upgrade to `jsonslicer` version 0.1.5 or newer: `pip install --upgrade jsonslicer`.
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)`.