json-expand-o-matic


Namejson-expand-o-matic JSON
Version 0.2.4 PyPI version JSON
download
home_pagehttps://github.com/jcejohnson/JsonExpandOMatic
SummaryExpand a dict into a collection of subdirectories and json files or contract (un-expand) the output of expand() into a dict.
upload_time2023-05-28 21:39:48
maintainer
docs_urlNone
authorJames Johnson
requires_python
license
keywords json jsonref
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jcejohnson/JsonExpandOMatic",
    "name": "json-expand-o-matic",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "json,jsonref",
    "author": "James Johnson",
    "author_email": "jcejohnson@users.noreply.github.com",
    "download_url": "https://files.pythonhosted.org/packages/23/a9/388d3fbf7cc202e1107cbe8f4e7fe7a207a4b6cf24c865a06c066fa3e6bb/json_expand_o_matic-0.2.4.tar.gz",
    "platform": null,
    "description": "# JSON Expand-O-Matic\n\nExpand a dict into a collection of subdirectories and json files or contract (un-expand) the output of expand() into a dict.\n\n## Overview\n\nConstruct\n\n    expandomatic = JsonExpandOMatic(path=data_path, logger=logger)\n\nExpand -- become or make larger or more extensive.\n\n    data = { ... }\n\n    data_path = sys.argv[1] if len(sys.argv) > 1 else '.'\n\nCreate {data_path}/root.json and {data_path}/root/...\n\n    expandomatic.expand(data)\n\nCreate {data_path}/foo.json and {data_path}/foo/...\n\n    expandomatic.expand(foo, root_element='foo')\n\n    Warning: expand() is destructive unless `preserve=True`\n\nContract -- decrease in size, number, or range.\n\n    data = expandomatic.contract()\n\nOr use jsonref\n\n    import jsonref\n    with open(f'{data_path}/root.json') as f:\n        data = jsonref.load(f, base_uri=f'file://{os.path.abspath(data_path)}/')\n\n## Quick Start\n\nSetup wrapper scripts:\n\n    ./wrapper.sh\n\nInstall for development:\n\n    ./tox.sh\n\nDo a thing:\n\n    rm -rf output\n    ./expand.sh output tests/testresources/actor-data.json 2>&1 | tee log.txt\n    find output -type f | sort\n\nDo another thing:\n\n    rm -rf output\n    ./expand.sh output tests/testresources/actor-data.json '[{\"/root/actors/.*\": [\"/[^/]+/movies/.*\"]}]' 2>&1 | tee log.txt\n    find output -type f | sort\n\n## Testing\n\nInstall & use tox:\n\n    ./tox.sh\n\nUpdate requirements.txt and dev-requirements.txt:\n\n    ./tox.sh -e deps\n\nReformat the code to make it pretty:\n\n    ./tox.sh -e fmt\n\nManually run the commands:\n\n    ./wrapper.sh\n    ./expand.sh output tests/testresources/actor-data.json\n    ./contract.sh output | jq -S . > output.json\n    ls -l output.json tests/testresources/actor-data.json\n    cmp output.json <(jq -S . tests/testresources/actor-data.json)\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Expand a dict into a collection of subdirectories and json files or contract (un-expand) the output of expand() into a dict.",
    "version": "0.2.4",
    "project_urls": {
        "Homepage": "https://github.com/jcejohnson/JsonExpandOMatic"
    },
    "split_keywords": [
        "json",
        "jsonref"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7ab7a235eeff6b3201f24a5716a61647e9efce21ae8f70f748358be47a457f00",
                "md5": "a5961c17a744f7b986dc3bd966fb12a8",
                "sha256": "dd15d0c8af53d2f84eba933631892be03fe596c60b1bc0f2f4440eb47e8693a7"
            },
            "downloads": -1,
            "filename": "json_expand_o_matic-0.2.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a5961c17a744f7b986dc3bd966fb12a8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 14295,
            "upload_time": "2023-05-28T21:39:47",
            "upload_time_iso_8601": "2023-05-28T21:39:47.033932Z",
            "url": "https://files.pythonhosted.org/packages/7a/b7/a235eeff6b3201f24a5716a61647e9efce21ae8f70f748358be47a457f00/json_expand_o_matic-0.2.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "23a9388d3fbf7cc202e1107cbe8f4e7fe7a207a4b6cf24c865a06c066fa3e6bb",
                "md5": "14fb4f07edb7e5fa9dd0047a737d4baf",
                "sha256": "248f45562f00fbf41a6601f330293d03422f366716e11d23365c5b951d436b06"
            },
            "downloads": -1,
            "filename": "json_expand_o_matic-0.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "14fb4f07edb7e5fa9dd0047a737d4baf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 17450,
            "upload_time": "2023-05-28T21:39:48",
            "upload_time_iso_8601": "2023-05-28T21:39:48.740505Z",
            "url": "https://files.pythonhosted.org/packages/23/a9/388d3fbf7cc202e1107cbe8f4e7fe7a207a4b6cf24c865a06c066fa3e6bb/json_expand_o_matic-0.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-28 21:39:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jcejohnson",
    "github_project": "JsonExpandOMatic",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "json-expand-o-matic"
}
        
Elapsed time: 1.73723s