Code Sample

import pandas as pd
import numpy as np

arrays = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'], ['one',
    'two', 'one', 'two', 'one', 'two', 'one', 'two']]

tuples = list(zip(*arrays))
index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
series = pd.Series(np.random.randn(8), index=index)

print(series.to_json())

Output:

{"["bar","one"]":-0.0591166327,"["bar","two"]":0.871145093,"["baz","one"]":0.61280938,"["baz","two"]":0.3848564991,"["foo","one"]":-0.8986592304,"["foo","two"]":-0.4631529084,"["qux","one"]":-1.3482521044,"["qux","two"]":0.5209236198}

Problem description

The output contains unescaped quotation marks, which makes the output invalid json.

Expected Output

Quote marks should be escaped, for example:

{"[\"bar\",\"one\"]":-0.0591166327,"[\"bar\",\"two\"]":0.871145093,"[\"baz\",\"one\"]":0.61280938,"[\"baz\",\"two\"]":0.3848564991,"[\"foo\",\"one\"]":-0.8986592304,"[\"foo\",\"two\"]":-0.4631529084,"[\"qux\",\"one\"]":-1.3482521044,"[\"qux\",\"two\"]":0.5209236198}

Output of pd.show_versions()

I reproduced it in pandas install from master:

INSTALLED VERSIONS ------------------ commit: None python: 3.6.0.final.0 python-bits: 64 OS: Linux OS-release: 4.8.8-200.fc24.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_AU.UTF-8 LOCALE: en_AU.UTF-8 pandas: 0.19.0+401.g8452080 nose: None pip: 9.0.1 setuptools: 27.2.0 Cython: 0.25.2 numpy: 1.12.0 scipy: None statsmodels: None xarray: None IPython: None sphinx: None patsy: None dateutil: 2.6.0 pytz: 2016.10 blosc: None bottleneck: None tables: None numexpr: None feather: None matplotlib: None openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: None httplib2: None apiclient: None sqlalchemy: None pymysql: None psycopg2: None jinja2: None s3fs: None pandas_datareader: None

Comment From: jreback

thanks this was just reported and is a duplicate of #15273

welcome to do a pull request to fix!