Expand a dict into a collection of subdirectories and json files or contract (un-expand) the output of expand() into a dict.
Project description
JSON Expand-O-Matic
Expand a dict into a collection of subdirectories and json files or contract (un-expand) the output of expand() into a dict.
Overview
Construct
expandomatic = JsonExpandOMatic(path=data_path, logger=logger)
Expand -- become or make larger or more extensive.
data = { ... }
data_path = sys.argv[1] if len(sys.argv) > 1 else '.'
Create {data_path}/root.json and {data_path}/root/...
expandomatic.expand(data)
Create {data_path}/foo.json and {data_path}/foo/...
expandomatic.expand(foo, root_element='foo')
Warning: expand() is destructive unless `preserve=True`
Contract -- decrease in size, number, or range.
data = expandomatic.contract()
Or use jsonref
import jsonref
f = open(f'{data_path}/root.json') # Yes, use a context.
data = jsonref.load(f, base_uri=f'file://{os.path.abspath(data_path)}/')
Quick Start
Setup wrapper scripts:
./wrapper.sh
Install for development:
./expand.sh --version
Do a thing:
rm -rf output
./expand.sh output tests/testresources/actor-data.json 2>&1 | tee log.txt
find output -type f | sort
Do another thing:
rm -rf output
./expand.sh output tests/testresources/actor-data.json '[{"/root/actors/.*": ["/[^/]+/movies/.*"]}]' 2>&1 | tee log.txt
find output -type f | sort
Testing
Install & use tox:
./tox.sh
Update requirements.txt and dev-requirements.txt:
./tox.sh -e deps
Reformat the code to make it pretty:
./tox.sh -e fmt
Manually run the commands:
./wrapper.sh
./expand.sh output tests/testresources/actor-data.json
./contract.sh output | jq -S . > output.json
ls -l output.json tests/testresources/actor-data.json
cmp output.json <(jq -S . tests/testresources/actor-data.json)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for json_expand_o_matic-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 529c5f73608dc119d175831576af83bfdd437ffcc3d5b2185c305f5275158d99 |
|
MD5 | 6915fa39eb9b0a5a57affcbc10da155a |
|
BLAKE2b-256 | 39c11fc88d90738b8cf175b460e2c548c9376b2253a4f87c487d89e6c714066b |
Hashes for json_expand_o_matic-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d56d28df72ec88aaee69b4f7b5404790e3e397dd1b94e270542bf038ac981fc |
|
MD5 | 3c6b0d46b3b490a5c5f4cd7a0988151d |
|
BLAKE2b-256 | c2cf4c433ed8b09af0f5eb1b1d82ff33b59fa593d69d136147637977c46e6c67 |