Skip to main content

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
with open(f'{data_path}/root.json') as f:
    data = jsonref.load(f, base_uri=f'file://{os.path.abspath(data_path)}/')

Quick Start

Setup wrapper scripts:

./wrapper.sh

Install for development:

./tox.sh

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

json_expand_o_matic-0.2.3.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

json_expand_o_matic-0.2.3-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file json_expand_o_matic-0.2.3.tar.gz.

File metadata

  • Download URL: json_expand_o_matic-0.2.3.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for json_expand_o_matic-0.2.3.tar.gz
Algorithm Hash digest
SHA256 d3beba3934688662d2d00b504d1a4e25245d967974bb3e1617bde17134137454
MD5 a4501d8de50367c3be9a4ad1c93729ac
BLAKE2b-256 c7dc295ed5bef3bb3124d9386c42f273ca057f28b9c9d338b491bb72f149822c

See more details on using hashes here.

File details

Details for the file json_expand_o_matic-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for json_expand_o_matic-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9a14ab5c870a373a2dda43ee502df8d6d821f9ff536581c2d235a16e444699da
MD5 84e2cd6dcda0c68b5b720e87722346d7
BLAKE2b-256 ac6646ce2cdd19c6cd80de15cf212449673b30c0fb8a1d1a02c4c93a0603d81c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page