pandas.DataFrame.to_json

DataFrame.to_json(path_or_buf=None, orient=None, date_format='epoch', double_precision=10, force_ascii=True)

Convert the object to a JSON string.

Note NaN’s and None will be converted to null and datetime objects will be converted to UNIX timestamps.

Parameters :

path_or_buf : the path or buffer to write the result string

if this is None, return a StringIO of the converted string

orient : string

  • Series
    • default is ‘index’
    • allowed values are: {‘split’,’records’,’index’}
  • DataFrame
    • default is ‘columns’
    • allowed values are: {‘split’,’records’,’index’,’columns’,’values’}
  • The format of the JSON string
    • split : dict like {index -> [index], columns -> [columns], data -> [values]}
    • records : list like [{column -> value}, ... , {column -> value}]
    • index : dict like {index -> {column -> value}}
    • columns : dict like {column -> {index -> value}}
    • values : just the values array

date_format : type of date conversion (epoch = epoch milliseconds, iso = ISO8601)

default is epoch

double_precision : The number of decimal places to use when encoding

floating point values, default 10.

force_ascii : force encoded string to be ASCII, default True.

Returns :

result : a JSON compatible string written to the path_or_buf;

if the path_or_buf is none, return a StringIO of the result