jsonasobj
raw JSON → 1.3.1 verified Mon Apr 27 auth: no python
A Python library for treating JSON data as Python objects, providing dict-like access with attribute-style syntax. Current version is 1.3.1 (stable) with v2.0.x pre-releases introducing breaking changes. Development is ongoing with pre-release versions.
pip install jsonasobj Common errors
error ModuleNotFoundError: No module named 'jsonasobj2' ↓
cause Trying to import v2 under v1 package name.
fix
Use
from jsonasobj import JsonObj for v1.x, or install v2 pre-release with pip install jsonasobj==2.0.2dev4 and import from jsonasobj2. error AttributeError: 'JsonObj' object has no attribute 'from_json' ↓
cause The method 'from_json' does not exist; a class method for construction from JSON string may have been removed.
fix
Use
JsonObj(json.loads(json_string)) instead. Warnings
breaking Version 2 pre-releases (jsonasobj2) introduce a new package name and are not backwards compatible. ↓
fix Import from jsonasobj2 instead of jsonasobj, or pin to v1.3.1 for compatibility.
deprecated Python 2 support is deprecated in v1.3.x and completely removed in v2. ↓
fix Upgrade to Python 3 and use latest version.
gotcha JsonObj inherits from dict, but setting attributes via dot notation does not update the underlying dict keys. ↓
fix Use dict-style assignment (obj['key'] = value) to keep dict and attribute in sync.
Install
pip install jsonasobj==2.0.2dev4 Imports
- JsonObj wrong
from jsonasobj2 import JsonObjcorrectfrom jsonasobj import JsonObj
Quickstart
from jsonasobj import JsonObj
data = JsonObj(name="test", count=42)
print(data.name) # test
print(data['count']) # 42