Registry / serialization / jsonslicer

jsonslicer

JSON →
library0.1.8pypypiunverified

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 jsonslicer
INSTALL
IMPORT
SIG · JSONSLICER
J
jsonslicer
serializationpythonv0.1.8
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
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
build_error
glibc
py 3.103.920 runs
build_error
Code
Verified usage

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

JsonSlicer
from jsonslicer import JsonSlicer

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.

import os import json from jsonslicer import JsonSlicer # Create a dummy JSON file for demonstration data = { "friends": [ {"name": "John", "age": 31}, {"name": "Ivan", "age": 26} ], "colleagues": { "manager": {"name": "Jack", "age": 33}, "subordinate": {"name": "Lucy", "age": 21} } } with open('people.json', 'w') as f: json.dump(data, f) # Extract a specific element with open('people.json') as data_file: ivans_age = next(JsonSlicer(data_file, ('friends', 1, 'age'))) print(f"Ivan's age: {ivans_age}") # Expected: Ivan's age: 26 # Iterate over a collection using wildcards (None) with open('people.json') as data_file: print("\nFriends:") for person in JsonSlicer(data_file, ('friends', None)): print(person) # Expected: {'name': 'John', 'age': 31}, {'name': 'Ivan', 'age': 26} # Iterate over different types of collections at once with open('people.json') as data_file: print("\nAll people:") for person in JsonSlicer(data_file, (None, None)): print(person) # Expected: all 4 people objects # Clean up the dummy file os.remove('people.json')
Debug
Known issues
gotchaInstallation requires a C++ compiler and `pkg-config` to build the YAJL dependency, which might fail on systems without proper development tools.
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`.
affects: All versions
gotchaFor 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.
fix
When reading from a file, open it in binary read mode: `with open('file.json', 'rb') as data: JsonSlicer(data, ...)`.
affects: All versions
gotchaWhile 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.
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.
affects: All versions
deprecatedVersions prior to 0.1.5 might have compatibility issues with Python 3.8 and newer due to a compatibility fix introduced in that release.
fix
Upgrade to `jsonslicer` version 0.1.5 or newer: `pip install --upgrade jsonslicer`.
affects: <0.1.5
gotchaThe `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.
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)`.
affects: All versions
Upgrade
Version history
0.1.8latest on PyPI · released Oct 25, 2022
Audit
Dependencies
yajlrequiredCore C library dependency for JSON parsing. Version 2.0.3+ required.
pkg-configrequiredBuild-time dependency for locating YAJL.
C++ compilerrequiredBuild-time dependency as the core module is written in C.
Agent activity
8 hits · last 30 days
node
6
Amazon
1
Resources