JSONFile Class¶
- class JSONFile(f_path=None, data=None, mother=None)
Purpose¶
JSONFile is a mutable mapping backed by a JSON document or a nested JSON
sub-object.
Example¶
from piethorn.filehandle.filehandling import JSONFile
config = JSONFile("config.json")
config["debug"] = True
config.setdefault("retries", 3)
Methods¶
exists(),has_path(),has_mother()Storage-state helpers.
load()/save()Synchronize in-memory data with storage.
config.load() config.save()
get(key, default=None)/fast_get(key, default=None)Reloading and non-reloading retrieval helpers.
config.get("debug", False) config.fast_get("debug", False)
setdefault(key, default=None),pop(key),popitem(),clear()Mutate and persist immediately.
config.setdefault("theme", "dark") config.pop("theme") config.clear()
pathed_as(other)Return whether another
JSONFilepoints at the same storage location.
Behavior notes¶
When a stored value is a dict, get and indexed lookup return another
JSONFile representing that nested object.