json-numpy
Description
json-numpy provides lossless and quick JSON encoding/decoding for NumPy arrays and scalars.
json-numpy follows Semantic Versioning.
Installation
json-numpy can be installed using pip:
$ 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.
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.
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:
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 to automatically test across the supported python versions, then run:
$ tox
Issue tracker
Please report any bugs or enhancement ideas using the issue tracker.
License
json-numpy is licensed under the terms of the MIT License (see LICENSE.txt for more information).
Metadata
Release files for json-numpy 2.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| json_numpy-2.1.1.tar.gz | 9.0 kB | Without provenance | Details for json_numpy-2.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| json_numpy-2.1.1-py3-none-any.whl | Python 3 | none | any | Details for json_numpy-2.1.1-py3-none-any.whl |
Total release size: 14.5 kB
Release files / json_numpy-2.1.1.tar.gz
| Download URL | json_numpy-2.1.1.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e6260fc29626e7a6a60d52a1f9ad8f522a9051f57ac55d5dfdeeaba55d4a835
|
|
BLAKE2b-256 checksum How to use checksums |
8341c37467c113c72742501c45974f70efbec94243cd357b93e18a1dc205a54a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.16
|
Release files / json_numpy-2.1.1-py3-none-any.whl
| Download URL | json_numpy-2.1.1-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91e45b756c1345f478651c3d7e767a7488335f34a3d500ef7829b917a8043c28
|
|
BLAKE2b-256 checksum How to use checksums |
cc617bec579093bc5f8da7f308a319e0d9372409f4bc0f7ea95588051b8cf139
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.16
|
Security for json-numpy 2.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.