I want to export some rows from a Pandas DataFrame to JSON. However, when exporting a columns I got an error:
TypeError: False is not JSON serializable
or
TypeError: 0 is not JSON serializable
I looked up in my data and the problem occurs for numpy.int64 and numpy.bool_ (numpy.float64 works fine).
For example, the problem appears for the following:
import pandas as pd
import simplejson as json
df = pd.DataFrame([[False,0],[True,1]], columns=['a','b'])
json.dumps(df.ix[0].to_dict())
(The same thing happens for dict(df.ix[0])).
Is there a simple workaround to export Pandas Series to JSON?
Or at least, a function that coerce any numpy type to the closest type compatible with JSON?