real-json


Namereal-json JSON
Version 1.0.5 PyPI version JSON
download
home_page
SummaryWrapper class so that you can access `dict` and `list` as easily as in Javascript
upload_time2023-03-10 06:16:59
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT License Copyright (c) 2023 Harold Alcala Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords json js javascript wrapper
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # python_js_json
Wrapper class so that you can access `dict` and `list` as easily as in Javascript

## Installation

    python3 -m pip install real_json

## usage

    ```python
    import real_json
    import json

    data = {
        "a": 1,
        "b": 2,
        "c": {
            "d": 3,
            "e": 4,
        },
        "f": [5, 6, 7],
    }
    wrapped = real_json.ify(data)

    # Test attribute access
    assert wrapped.a == 1
    assert wrapped.b == 2
    assert wrapped.c.d == 3
    assert wrapped.c.e == 4
    assert wrapped.f[0] == 5
    assert wrapped.f[1] == 6
    assert wrapped.f[2] == 7
    assert wrapped.f[3] == None
    assert wrapped.g == None
    assert wrapped.c.f == None

    # Test item access
    assert wrapped["a"] == 1
    assert wrapped["b"] == 2
    assert wrapped["c"]["d"] == 3
    assert wrapped["c"]["e"] == 4
    assert wrapped["f"][0] == 5
    assert wrapped["f"][1] == 6
    assert wrapped["f"][2] == 7
    assert wrapped["g"] == None
    assert wrapped["c"]["f"] == None

    # Test set attribute
    wrapped.a = 10
    assert wrapped.a == 10
    wrapped.g = 20
    assert wrapped.g == 20

    # Test set item
    wrapped["b"] = 20
    assert wrapped["b"] == 20
    wrapped["h"] = 30
    assert wrapped["h"] == 30

    # Test str and repr
    assert str(wrapped) == str(data)
    assert repr(wrapped) == repr(data)

    # Test len
    print("wrapped:", wrapped)
    assert len(wrapped) == 6
    assert len(wrapped.c) == 2
    assert len(wrapped.f) == 3

    # Test bool
    assert bool(wrapped) == True
    assert bool(wrapped.g) == True
    assert bool(wrapped.c) == True
    assert bool(wrapped.f)

    json.dump(wrapped.__dict__["_data"], "wrapped.json")

    data = {
        "name": "John",
        "age": 30,
        "cars": [
            {"model": "Ford", "year": 2020},
            {"model": "BMW", "year": 2019}
        ]
    }

    wrapped_data = real_json.ify(data)

    # Accessing values using dot notation
    print(wrapped_data.name)  # Output: "John"
    print(wrapped_data.age)  # Output: 30
    # Output: [{"model": "Ford", "year": 2020}, {"model": "BMW", "year": 2019}]
    print(wrapped_data.cars)

    # Accessing values using square brackets notation
    print(wrapped_data['name'])  # Output: "John"
    print(wrapped_data['age'])  # Output: 30
    # Output: [{"model": "Ford", "year": 2020}, {"model": "BMW", "year": 2019}]
    print(wrapped_data['cars'])

    # Accessing values that are not present in the data
    print(wrapped_data.address)  # Output: None
    print(wrapped_data['address'])  # Output: None

    # Accessing elements of the list using index notation
    print(wrapped_data.cars[0])  # Output: {"model": "Ford", "year": 2020}
    print(wrapped_data['cars'][0])  # Output: {"model": "Ford", "year": 2020}

    # Accessing elements of the list using index notation
    print(wrapped_data.cars[0].model)  # Output: "Ford"
    print(wrapped_data['cars'][0]['model'])  # Output: "Ford"

    # Accessing elements of the list using index notation
    print(wrapped_data.cars[2])  # Output: None
    print(wrapped_data['cars'][2])  # Output: None

    # Accessing elements of the list using index notation
    print(wrapped_data.cars[0].color)  # Output: None
    print(wrapped_data['cars'][0]['color'])  # Output: None

    json.dump(wrapped_data.__dict__["_data"], "data.json")
    ```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "real-json",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "json,js,Javascript,wrapper",
    "author": "",
    "author_email": "Harold Alcala <harold.dev@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/c4/21/535988ccf3f05657020ef928da2e0d3926e1d37b8af0aaf6f46dd1495fe5/real_json-1.0.5.tar.gz",
    "platform": null,
    "description": "# python_js_json\nWrapper class so that you can access `dict` and `list` as easily as in Javascript\n\n## Installation\n\n    python3 -m pip install real_json\n\n## usage\n\n    ```python\n    import real_json\n    import json\n\n    data = {\n        \"a\": 1,\n        \"b\": 2,\n        \"c\": {\n            \"d\": 3,\n            \"e\": 4,\n        },\n        \"f\": [5, 6, 7],\n    }\n    wrapped = real_json.ify(data)\n\n    # Test attribute access\n    assert wrapped.a == 1\n    assert wrapped.b == 2\n    assert wrapped.c.d == 3\n    assert wrapped.c.e == 4\n    assert wrapped.f[0] == 5\n    assert wrapped.f[1] == 6\n    assert wrapped.f[2] == 7\n    assert wrapped.f[3] == None\n    assert wrapped.g == None\n    assert wrapped.c.f == None\n\n    # Test item access\n    assert wrapped[\"a\"] == 1\n    assert wrapped[\"b\"] == 2\n    assert wrapped[\"c\"][\"d\"] == 3\n    assert wrapped[\"c\"][\"e\"] == 4\n    assert wrapped[\"f\"][0] == 5\n    assert wrapped[\"f\"][1] == 6\n    assert wrapped[\"f\"][2] == 7\n    assert wrapped[\"g\"] == None\n    assert wrapped[\"c\"][\"f\"] == None\n\n    # Test set attribute\n    wrapped.a = 10\n    assert wrapped.a == 10\n    wrapped.g = 20\n    assert wrapped.g == 20\n\n    # Test set item\n    wrapped[\"b\"] = 20\n    assert wrapped[\"b\"] == 20\n    wrapped[\"h\"] = 30\n    assert wrapped[\"h\"] == 30\n\n    # Test str and repr\n    assert str(wrapped) == str(data)\n    assert repr(wrapped) == repr(data)\n\n    # Test len\n    print(\"wrapped:\", wrapped)\n    assert len(wrapped) == 6\n    assert len(wrapped.c) == 2\n    assert len(wrapped.f) == 3\n\n    # Test bool\n    assert bool(wrapped) == True\n    assert bool(wrapped.g) == True\n    assert bool(wrapped.c) == True\n    assert bool(wrapped.f)\n\n    json.dump(wrapped.__dict__[\"_data\"], \"wrapped.json\")\n\n    data = {\n        \"name\": \"John\",\n        \"age\": 30,\n        \"cars\": [\n            {\"model\": \"Ford\", \"year\": 2020},\n            {\"model\": \"BMW\", \"year\": 2019}\n        ]\n    }\n\n    wrapped_data = real_json.ify(data)\n\n    # Accessing values using dot notation\n    print(wrapped_data.name)  # Output: \"John\"\n    print(wrapped_data.age)  # Output: 30\n    # Output: [{\"model\": \"Ford\", \"year\": 2020}, {\"model\": \"BMW\", \"year\": 2019}]\n    print(wrapped_data.cars)\n\n    # Accessing values using square brackets notation\n    print(wrapped_data['name'])  # Output: \"John\"\n    print(wrapped_data['age'])  # Output: 30\n    # Output: [{\"model\": \"Ford\", \"year\": 2020}, {\"model\": \"BMW\", \"year\": 2019}]\n    print(wrapped_data['cars'])\n\n    # Accessing values that are not present in the data\n    print(wrapped_data.address)  # Output: None\n    print(wrapped_data['address'])  # Output: None\n\n    # Accessing elements of the list using index notation\n    print(wrapped_data.cars[0])  # Output: {\"model\": \"Ford\", \"year\": 2020}\n    print(wrapped_data['cars'][0])  # Output: {\"model\": \"Ford\", \"year\": 2020}\n\n    # Accessing elements of the list using index notation\n    print(wrapped_data.cars[0].model)  # Output: \"Ford\"\n    print(wrapped_data['cars'][0]['model'])  # Output: \"Ford\"\n\n    # Accessing elements of the list using index notation\n    print(wrapped_data.cars[2])  # Output: None\n    print(wrapped_data['cars'][2])  # Output: None\n\n    # Accessing elements of the list using index notation\n    print(wrapped_data.cars[0].color)  # Output: None\n    print(wrapped_data['cars'][0]['color'])  # Output: None\n\n    json.dump(wrapped_data.__dict__[\"_data\"], \"data.json\")\n    ```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Harold Alcala  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Wrapper class so that you can access `dict` and `list` as easily as in Javascript",
    "version": "1.0.5",
    "split_keywords": [
        "json",
        "js",
        "javascript",
        "wrapper"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "82ab1794e072356d9f24ee84d4d512fd2c87dac5e4a73868ff3926b9c17a246b",
                "md5": "8d058c38f26d373e3dfcc8b4788e36c8",
                "sha256": "23e7c0c5ae7c342559da1b21f4003a7cec36fca2ea53617c9b8326ed59d4ac47"
            },
            "downloads": -1,
            "filename": "real_json-1.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8d058c38f26d373e3dfcc8b4788e36c8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4518,
            "upload_time": "2023-03-10T06:16:57",
            "upload_time_iso_8601": "2023-03-10T06:16:57.659284Z",
            "url": "https://files.pythonhosted.org/packages/82/ab/1794e072356d9f24ee84d4d512fd2c87dac5e4a73868ff3926b9c17a246b/real_json-1.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c421535988ccf3f05657020ef928da2e0d3926e1d37b8af0aaf6f46dd1495fe5",
                "md5": "942cac362e0f5eda04d8db61ddfc8af2",
                "sha256": "853143c89d7a0b4887888548df82d6a791452c4ee47c0876927b9238886cacd9"
            },
            "downloads": -1,
            "filename": "real_json-1.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "942cac362e0f5eda04d8db61ddfc8af2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 3867,
            "upload_time": "2023-03-10T06:16:59",
            "upload_time_iso_8601": "2023-03-10T06:16:59.379856Z",
            "url": "https://files.pythonhosted.org/packages/c4/21/535988ccf3f05657020ef928da2e0d3926e1d37b8af0aaf6f46dd1495fe5/real_json-1.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-10 06:16:59",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "real-json"
}
        
Elapsed time: 0.05711s