Metadata-Version: 2.1
Name: json-numpy
Version: 1.0.0a1
Summary: JSON encoding/decoding for Numpy arrays and scalars
Home-page: https://github.com/Crimson-Crow/json-numpy
Author: Crimson-Crow
Author-email: github@crimsoncrow.dev
License: MIT
Project-URL: Bug Reports, https://github.com/Crimson-Crow/json-numpy/issues
Project-URL: Source, https://github.com/Crimson-Crow/json-numpy
Keywords: json numpy serialization encoding
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Utilities
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
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 :: 3 :: Only
Requires-Python: >=3.6, <4
Description-Content-Type: text/markdown
License-File: LICENSE.txt

json-numpy
==========

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

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

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

`json-numpy` can be installed using [`pip`](http://www.pip-installer.org/):

    $ pip install json-numpy

Alternatively, you can download the repository and run the following command from within the source directory:

    $ python setup.py install

Usage
-----

For a quick start, `json_numpy` can be used as a basic 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.

Development
-----------
The latest source code can be obtained from [GitHub](https://github.com/Crimson-Crow/json-numpy).

`json-numpy` maintains compatibility with python versions >= 3.6.

Install [`tox`](https://tox.readthedocs.io/en/latest/) to support testing across multiple python versions in your development environment.
If you use [`conda`](https://docs.conda.io/en/latest/) to install `python` use [`tox-conda`](https://github.com/tox-dev/tox-conda) to automatically manage
testing across all supported python versions.
    
    # Using a system python
    $ pip install tox

    # Additionally, using a conda-provided python
    $ pip install tox tox-conda

Execute tests across supported python versions:
    
    $ tox

License
-------

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

