Note

Note that each main class and module has a help() method, accessible via <class/module>.help(). These help() methods are simply docstring printers and hinters, so they will not be touched on in this documentation.

« Back (load.py) Next » (delete.py)
   

edit.py

This module houses the class Edit. Despite being implemented a bit later than the other helper classes, this one is just as equally as important, as it allows remote editing of JSON data stored with Storage.store().

Structure of the Module

Tip

Click on a class or method below to go straight to its documentation!

Storage.Edit

Methods

Storage.Edit.propkey()

@classmethod
def propkey(cls,
            file_path: str,
            top_lv_key: Any,
            oldpropkey: str,
            newpropkey: str,
            noexist_ok: bool=True
           ) -> None

Rename a subkey within a top-level key.

Arguments
Symbol Type Hint Default Description
file_path str Required Path to JSON file.
top_lv_key Any Required Top-level key (recommended str).
oldpropkey str Required Existing subkey to rename.
newpropkey str Required New name for the subkey.
new bool True (DEPRECATED) Deprecated alias for noexist_ok.
noexist_ok bool True If True, create newpropkey with empty value when oldpropkey missing; otherwise raise KeyNotFoundError.
Outputs
Example
Storage.Edit.propkey("db.json", "users", "username", "user_name")

Storage.Edit.propval()

@classmethod
def propval(cls,
            file_path: str,
            top_lv_key: Any,
            propkey: str,
            newval: str
           ) -> None

Changes the value for an existing subkey under a top-level key.

Arguments
Symbol Type Hint Default Description
file_path str Required Path to JSON file.
top_lv_key Any Required Top-level key (recommended str).
propkey str Required Subkey whose value will be changed.
newval str Required New value for the subkey.
Outputs
Example
Storage.Edit.propval("db.json", "users", "alice", "new-id")

Storage.Edit.key()

@classmethod
def key(cls, file_path: str, oldkey: Any, newkey: Any) -> None

Renames any top-level key in the JSON file; values stay unchanged.

Arguments
Symbol Type Hint Default Description
file_path str Required Path to JSON file.
oldkey Any Required Existing top-level key to rename.
newkey Any Required New top-level key name.
Outputs
Example
Storage.Edit.key("db.json", "users", "accounts")

Other Info