Metadata-Version: 2.1
Name: json_expand_o_matic
Version: 0.2.1
Summary: Expand a dict into a collection of subdirectories and json files or contract (un-expand) the output of expand() into a dict.
Home-page: https://github.com/jcejohnson/JsonExpandOMatic
Author: James Johnson
Author-email: jcejohnson@users.noreply.github.com
Keywords: json,jsonref
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Build Tools
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: Implementation :: PyPy
Description-Content-Type: text/markdown
License-File: LICENSE.txt

# 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)
