Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ujson can not encode numpy array

numpy array

x = np.array([1,2,3,4])

ujson.encode

ujson.encode(x, ensure_ascii=False, double_precision=-1)

gives me error

OverflowError: Maximum recursion level reached

version info

ujson 1.33
python 3.4.3

It seems to be that ujson can not encode numpy array and gives confusing error message.

By the way, where can I find the documentation of ujson. thx

like image 635
Hello lad Avatar asked Oct 31 '22 23:10

Hello lad


1 Answers

Make sure to convert any numpy arrays to regular lists before jsonification. Hence,

ujson.encode(x.tolist())

should work (Python 3.5.3; ujson 1.35).

ujson documentation: https://github.com/esnme/ultrajson

Btw, there's an issue for what you described.

like image 183
Tom Pohl Avatar answered Nov 15 '22 03:11

Tom Pohl