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:

./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

json_expand_o_matic-0.1.3.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

json_expand_o_matic-0.1.3-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: json_expand_o_matic-0.1.3.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for json_expand_o_matic-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b24cd32b30d106de5b3bbe2cc98cb004e0a92539e721d6d6a4a8163393a26912
MD5 43a6b16f19b5d005189e9e5c40e23bf0
BLAKE2b-256 266472591807c1f53d1c937bf3d74661d52e2e4cdf60d5fef0be4c334a686ffa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: json_expand_o_matic-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for json_expand_o_matic-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 50a0271e2c040b97865c040c6848639ba5f853d0740331b09c5f62cd6889b072
MD5 8d555eb81ca8ea41349f940323773c41
BLAKE2b-256 36b4485b2203487fd7bd62b401f9ed4b9b5fa07b6316984667c3cbfebcf8c4a3

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