Клонируем Ultra fast JSON decoder and encoder written in C with Python bindings and NumPy bindings
Вы cможете преобразовать данные Numpy int64 в данные JSON serializable ( Python ) , используя функцию ujson.dumps().
(.env) boris@boris-All-Series:~/CONVERTJS$ git clone https://github.com/caiyunapp/ultrajson
Cloning into 'ultrajson'...
remote: Enumerating objects: 1657, done.
remote: Total 1657 (delta 0), reused 0 (delta 0), pack-reused 1657
Receiving objects: 100% (1657/1657), 1.06 MiB | 1.97 MiB/s, done.
Resolving deltas: 100% (916/916), done.
(.env) boris@boris-All-Series:~/CONVERTJS$ ll
total 220
drwxrwxr-x 5 boris boris 4096 мая 31 19:55 ./
drwxr-xr-x 70 boris boris 4096 мая 31 19:50 ../
drwxrwxr-x 6 boris boris 4096 мая 31 19:51 .env/
drwxrwxr-x 6 boris boris 4096 мая 31 19:55 ultrajson/
drwxrwxr-x 5 boris boris 4096 мая 31 19:53 ultrajson-master/
-rw-rw-r-- 1 boris boris 202126 мая 31 19:52 ultrajson-master.zip
(.env) boris@boris-All-Series:~/CONVERTJS$ cd ultrajson
(.env) boris@boris-All-Series:~/CONVERTJS/ultrajson$ pip install -e .
Obtaining file:///home/boris/CONVERTJS/ultrajson
Collecting numpy>=1.16.4
Using cached numpy-1.22.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.9 MB)
Installing collected packages: numpy, nujson
Running setup.py develop for nujson
Successfully installed nujson numpy-1.22.4
(.env) boris@boris-All-Series:~/CONVERTJS/ultrajson$ cat NpInt64ToJSON.py
import numpy as np
import nujson as ujson
dict_np = {"key1": np.int64(3452), "key2": np.int64(5679),\
"key3": np.int64(1256),"key4": np.int64(8256),"key5": np.int64(8256) }
print(ujson.dumps(dict_np))
(.env) boris@boris-All-Series:~/CONVERTJS/ultrajson$ python3 NpInt64ToJSON.py
{"key1":3452,"key2":5679,"key3":1256,"key4":8256,"key5":8256}
(.env) boris@boris-All-Series:~/CONVERTJS/ultrajson$ cat NpInt64ToJSON1.py
import numpy as np
import nujson as ujson
spisok = [{1.0: np.int64(6851)}, {2.0: np.int64(8654)}, {3.0: np.int64(7694)}]
result = ujson.dumps(spisok)
print(result)
(.env) boris@boris-All-Series:~/CONVERTJS/ultrajson$ python3 NpInt64ToJSON1.py
[{"1.0":6851},{"2.0":8654},{"3.0":7694}]
No comments:
Post a Comment