json-numpy


Namejson-numpy JSON
Version 2.1.0 PyPI version JSON
download
home_pageNone
SummaryJSON encoding/decoding for Numpy arrays and scalars
upload_time2024-07-15 21:49:09
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2024 Crimson-Crow <github@crimsoncrow.dev> 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 numpy serialization encode decode encoding decoding
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            json-numpy
==========

[![PyPI](https://img.shields.io/pypi/v/json-numpy)](https://pypi.org/project/json-numpy/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/json-numpy)](https://pypi.org/project/json-numpy/)
[![GitHub](https://img.shields.io/github/license/Crimson-Crow/json-numpy)]((https://github.com/Crimson-Crow/json-numpy/blob/main/LICENSE.txt))
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://makeapullrequest.com)

Description
-----------

`json-numpy` provides lossless and quick JSON encoding/decoding for [NumPy](http://www.numpy.org/) arrays and scalars.

`json-numpy` follows [Semantic Versioning](https://semver.org/).

Installation
------------

`json-numpy` can be installed using [`pip`](https://pip.pypa.io/en/stable/):

    $ pip install json-numpy

Usage
-----

For a quick start, `json_numpy` can be used as a simple drop-in replacement of the built-in `json` module. \
The `dump()`, `load()`, `dumps()` and `loads()` methods are implemented by wrapping the original methods and replacing the default encoder and decoder. \
More information on the usage can be found in the `json` module's [documentation](https://docs.python.org/3/library/json.html).

```python
import numpy as np
import json_numpy

arr = np.array([0, 1, 2])
encoded_arr_str = json_numpy.dumps(arr)
decoded_arr = json_numpy.loads(encoded_arr_str)
```

Another way of using `json_numpy` is to explicitly use the provided encoder and decoder functions in conjunction with the `json` module.

```python
import json
import numpy as np
from json_numpy import default, object_hook

arr = np.array([0, 1, 2])
encoded_arr_str = json.dumps(arr, default=default)
decoded_arr = json.loads(encoded_arr_str, object_hook=object_hook)
```

Finally, the last way of using `json_numpy` is by monkey patching the `json` module after importing it first:

```python
import json
import numpy as np
import json_numpy

json_numpy.patch()

arr = np.array([0, 1, 2])
encoded_arr_str = json.dumps(arr)
decoded_arr = json.loads(encoded_arr_str)
```

This method can be used to change the behavior of a module depending on the `json` module without editing its code.

Tests
-----

The simplest way to run tests is:

    $ python -m unittest

As a more robust alternative, you can install [`tox`](https://tox.readthedocs.io/en/latest/install.html) to automatically test across the supported python versions, then run:

    $ tox

Issue tracker
-------------

Please report any bugs or enhancement ideas using the [issue tracker](https://github.com/Crimson-Crow/json-numpy/issues).

License
-------

`json-numpy` is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT) (see [LICENSE.txt](https://github.com/Crimson-Crow/json-numpy/blob/main/LICENSE.txt) for more information).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "json-numpy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Crimson-Crow <github@crimsoncrow.dev>",
    "keywords": "json, numpy, serialization, encode, decode, encoding, decoding",
    "author": null,
    "author_email": "Crimson-Crow <github@crimsoncrow.dev>",
    "download_url": "https://files.pythonhosted.org/packages/52/dd/62a50cdb5dad32be516dfddb40ef2f623d9525f5c42cf3738e01edeff872/json_numpy-2.1.0.tar.gz",
    "platform": null,
    "description": "json-numpy\r\n==========\r\n\r\n[![PyPI](https://img.shields.io/pypi/v/json-numpy)](https://pypi.org/project/json-numpy/)\r\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/json-numpy)](https://pypi.org/project/json-numpy/)\r\n[![GitHub](https://img.shields.io/github/license/Crimson-Crow/json-numpy)]((https://github.com/Crimson-Crow/json-numpy/blob/main/LICENSE.txt))\r\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://makeapullrequest.com)\r\n\r\nDescription\r\n-----------\r\n\r\n`json-numpy` provides lossless and quick JSON encoding/decoding for [NumPy](http://www.numpy.org/) arrays and scalars.\r\n\r\n`json-numpy` follows [Semantic Versioning](https://semver.org/).\r\n\r\nInstallation\r\n------------\r\n\r\n`json-numpy` can be installed using [`pip`](https://pip.pypa.io/en/stable/):\r\n\r\n    $ pip install json-numpy\r\n\r\nUsage\r\n-----\r\n\r\nFor a quick start, `json_numpy` can be used as a simple drop-in replacement of the built-in `json` module. \\\r\nThe `dump()`, `load()`, `dumps()` and `loads()` methods are implemented by wrapping the original methods and replacing the default encoder and decoder. \\\r\nMore information on the usage can be found in the `json` module's [documentation](https://docs.python.org/3/library/json.html).\r\n\r\n```python\r\nimport numpy as np\r\nimport json_numpy\r\n\r\narr = np.array([0, 1, 2])\r\nencoded_arr_str = json_numpy.dumps(arr)\r\ndecoded_arr = json_numpy.loads(encoded_arr_str)\r\n```\r\n\r\nAnother way of using `json_numpy` is to explicitly use the provided encoder and decoder functions in conjunction with the `json` module.\r\n\r\n```python\r\nimport json\r\nimport numpy as np\r\nfrom json_numpy import default, object_hook\r\n\r\narr = np.array([0, 1, 2])\r\nencoded_arr_str = json.dumps(arr, default=default)\r\ndecoded_arr = json.loads(encoded_arr_str, object_hook=object_hook)\r\n```\r\n\r\nFinally, the last way of using `json_numpy` is by monkey patching the `json` module after importing it first:\r\n\r\n```python\r\nimport json\r\nimport numpy as np\r\nimport json_numpy\r\n\r\njson_numpy.patch()\r\n\r\narr = np.array([0, 1, 2])\r\nencoded_arr_str = json.dumps(arr)\r\ndecoded_arr = json.loads(encoded_arr_str)\r\n```\r\n\r\nThis method can be used to change the behavior of a module depending on the `json` module without editing its code.\r\n\r\nTests\r\n-----\r\n\r\nThe simplest way to run tests is:\r\n\r\n    $ python -m unittest\r\n\r\nAs a more robust alternative, you can install [`tox`](https://tox.readthedocs.io/en/latest/install.html) to automatically test across the supported python versions, then run:\r\n\r\n    $ tox\r\n\r\nIssue tracker\r\n-------------\r\n\r\nPlease report any bugs or enhancement ideas using the [issue tracker](https://github.com/Crimson-Crow/json-numpy/issues).\r\n\r\nLicense\r\n-------\r\n\r\n`json-numpy` is licensed under the terms of the [MIT License](https://opensource.org/licenses/MIT) (see [LICENSE.txt](https://github.com/Crimson-Crow/json-numpy/blob/main/LICENSE.txt) for more information).\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Crimson-Crow <github@crimsoncrow.dev>  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": "JSON encoding/decoding for Numpy arrays and scalars",
    "version": "2.1.0",
    "project_urls": {
        "Homepage": "https://github.com/Crimson-Crow/json-numpy",
        "Issues": "https://github.com/Crimson-Crow/json-numpy/issues",
        "Repository": "https://github.com/Crimson-Crow/json-numpy.git"
    },
    "split_keywords": [
        "json",
        " numpy",
        " serialization",
        " encode",
        " decode",
        " encoding",
        " decoding"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2dceaa15955ac7035c53a6852fadc3049506e91c89641e814a5711264a8dc856",
                "md5": "08f5ecec0408dfed28cd2bcc0bfccd1e",
                "sha256": "366b5c38fe38f22f604e0f930abf1dee0028b06c1ae297302ebf945d0901e1a2"
            },
            "downloads": -1,
            "filename": "json_numpy-2.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "08f5ecec0408dfed28cd2bcc0bfccd1e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5441,
            "upload_time": "2024-07-15T21:49:07",
            "upload_time_iso_8601": "2024-07-15T21:49:07.984435Z",
            "url": "https://files.pythonhosted.org/packages/2d/ce/aa15955ac7035c53a6852fadc3049506e91c89641e814a5711264a8dc856/json_numpy-2.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "52dd62a50cdb5dad32be516dfddb40ef2f623d9525f5c42cf3738e01edeff872",
                "md5": "75219fa61649cffea66fdaa92194a198",
                "sha256": "7b2cf6e54c69c769f88480d12d0361f207c39d7626961b4b1ee92f3156425a15"
            },
            "downloads": -1,
            "filename": "json_numpy-2.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "75219fa61649cffea66fdaa92194a198",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 9522,
            "upload_time": "2024-07-15T21:49:09",
            "upload_time_iso_8601": "2024-07-15T21:49:09.186048Z",
            "url": "https://files.pythonhosted.org/packages/52/dd/62a50cdb5dad32be516dfddb40ef2f623d9525f5c42cf3738e01edeff872/json_numpy-2.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-15 21:49:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Crimson-Crow",
    "github_project": "json-numpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "json-numpy"
}
        
Elapsed time: 3.67140s