Make accessing JSON like data more convenient.
Project description
Objectify JSON
Make accessing JSON like data more convenient.
Features
- Access dict value via dot
.
(data.a.b.c
). - Always return
ObjectifyJSON
type, which holds the data with type of dict, list or any other primitive types. - Use
x._data
to get the real data. - Always return
ObjectifyJSON(None)
if doesn't exist. - An CLI tool named
object
to process JSON data.
Install
pip3 install objectify-json
Example
See test.py
Functions to process data in batch
- The return value is always
ObjectifyJOSN
too! - The return value of lambda funtions will always be unwrapped to primitive types.
- Most of the
fn_*
functions accept optionalunwrap
parameter to enable passing the underlying value as primitive types to lambda. Default is False. - When used in CLI tool, if it failed getting the property by property name, e.g.
map
, it will retry to get function with prefixfn_
added to the name. This will simplify writting the CLI command.
Common
Following methods of ObjectifyJOSN
accept optional unwrap
to unwrap ObjectifyJOSN
data to the underlying built-in data, the default value is False
.
fn_map(fn, unwrap=False)
:map
on the iteratorfn_reduce(fn, initializer=None, unwrap=False)
:reduce
on the iterator, lambda as the first positional parameter, optionalinitializer
parameter will be passed to built-inreduce
.fn_lambda(fn, unwrap=False)
: value in-and-outfn_filter(fn, unwrap=False)
:filter
on the iterator
Dict
fn_keys()
: Return keys as list.fn_values()
: Return values as list.fn_items()
: Return items as list. Element has the typetuple
, e.g.("key", "value")
.fn_include_keys(keys)
: Filter dict. Keep thekeys
you give.fn_exclude_keys(keys)
: Filter dict. Remove thekeys
you give.fn_filter_by_value(fn)
: Filter dict. Filter by the lambda you give, which accept the value of dict item.fn_filter_by_kv(fn)
: Filter dict. Filter by the lambda you give, which acceptkey
andvalue
two variables.fn_update(key, fn, unwrap=False)
: Update dict value. The lambda you give accept the origin value and return a new value.fn_items_update(fn, unwrap=False)
: Update dict value. The lambda you give acceptkey
andvalue
two variables and return a new value.fn_rename(mapping)
: Update dict key. Themapping
is a list of two-elements list.
List
fn_sort(fn)
: Sort the list in place. The lambda you give will be passed askey
argument to thesort
method of list.fn_dedup(fn=None, all=True)
: Dedup the elements in list. Ifall
ifFalse
, the duplication will checked by comparing current value between last value, else will compare to all appeared before.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file objectify_json-0.2.12-py3-none-any.whl
.
File metadata
- Download URL: objectify_json-0.2.12-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f515b3da43fcbce816e602b3c48a4798aa91c8ede94f536edf74ae0f91ae7997 |
|
MD5 | 0484c574c5169a8181808304abacd566 |
|
BLAKE2b-256 | f60d51408b9da577938b406ecda9ba94262c9dba05ac2eb47711f8a91956c02d |