Skip to content

DataFrame.to_json() creates invalid JSON with MultiIndex #10113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mathom opened this issue May 12, 2015 · 1 comment
Closed

DataFrame.to_json() creates invalid JSON with MultiIndex #10113

mathom opened this issue May 12, 2015 · 1 comment
Labels
IO JSON read_json, to_json, json_normalize MultiIndex

Comments

@mathom
Copy link

mathom commented May 12, 2015

Pandas will dump MultiIndex dataframes as invalid JSON in 0.16.0. For example this dataframe:

     0
a c  1
b d  2

Will dump as: {"0":{"["a","c"]":1,"["b","d"]":2}}. You can see that the keys aren't escaping their double quote character and this isn't readable as JSON.

The following snippet illustrates how to recreate this:

import pandas
df = pandas.DataFrame([1,2], index=[['a','b'],['c','d']])
pandas.read_json(df.to_json())

...

ValueError: No ':' found when decoding object value

My pandas versions:

pandas.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.6.final.0
python-bits: 64
OS: Darwin
OS-release: 14.3.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.16.0
nose: 1.3.6
Cython: None
numpy: 1.9.2
scipy: None
statsmodels: None
IPython: 3.1.0
sphinx: None
patsy: None
dateutil: 2.4.2
pytz: 2013b
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.4.3
openpyxl: None
xlrd: None
xlwt: 1.0.0
xlsxwriter: 0.5.5
lxml: None
bs4: 4.3.2
html5lib: 0.999
httplib2: 0.9.1
apiclient: 1.4.0
sqlalchemy: 0.9.3
pymysql: None
psycopg2: None
@jreback
Copy link
Contributor

jreback commented May 12, 2015

this is a dupe of #4889

this is Not Implemented, however, doing: df.reset_index().to_json() will work.

@jreback jreback closed this as completed May 12, 2015
@jreback jreback added IO JSON read_json, to_json, json_normalize MultiIndex labels May 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO JSON read_json, to_json, json_normalize MultiIndex
Projects
None yet
Development

No branches or pull requests

2 participants