<h4 dir="auto">Code Sample</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="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())"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-s1">arrays</span> <span class="pl-c1">=</span> [[<span class="pl-s">'bar'</span>, <span class="pl-s">'bar'</span>, <span class="pl-s">'baz'</span>, <span class="pl-s">'baz'</span>, <span class="pl-s">'foo'</span>, <span class="pl-s">'foo'</span>, <span class="pl-s">'qux'</span>, <span class="pl-s">'qux'</span>], [<span class="pl-s">'one'</span>,
    <span class="pl-s">'two'</span>, <span class="pl-s">'one'</span>, <span class="pl-s">'two'</span>, <span class="pl-s">'one'</span>, <span class="pl-s">'two'</span>, <span class="pl-s">'one'</span>, <span class="pl-s">'two'</span>]]

<span class="pl-s1">tuples</span> <span class="pl-c1">=</span> <span class="pl-en">list</span>(<span class="pl-en">zip</span>(<span class="pl-c1">*</span><span class="pl-s1">arrays</span>))
<span class="pl-s1">index</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">MultiIndex</span>.<span class="pl-en">from_tuples</span>(<span class="pl-s1">tuples</span>, <span class="pl-s1">names</span><span class="pl-c1">=</span>[<span class="pl-s">'first'</span>, <span class="pl-s">'second'</span>])
<span class="pl-s1">series</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">Series</span>(<span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">randn</span>(<span class="pl-c1">8</span>), <span class="pl-s1">index</span><span class="pl-c1">=</span><span class="pl-s1">index</span>)

<span class="pl-en">print</span>(<span class="pl-s1">series</span>.<span class="pl-en">to_json</span>())</pre></div>
<p dir="auto">Output:</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{&quot;[&quot;bar&quot;,&quot;one&quot;]&quot;:-0.0591166327,&quot;[&quot;bar&quot;,&quot;two&quot;]&quot;:0.871145093,&quot;[&quot;baz&quot;,&quot;one&quot;]&quot;:0.61280938,&quot;[&quot;baz&quot;,&quot;two&quot;]&quot;:0.3848564991,&quot;[&quot;foo&quot;,&quot;one&quot;]&quot;:-0.8986592304,&quot;[&quot;foo&quot;,&quot;two&quot;]&quot;:-0.4631529084,&quot;[&quot;qux&quot;,&quot;one&quot;]&quot;:-1.3482521044,&quot;[&quot;qux&quot;,&quot;two&quot;]&quot;:0.5209236198}"><pre class="notranslate">{<span class="pl-s"><span class="pl-pds">"</span>[<span class="pl-pds">"</span></span><span class="pl-ii">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</span>}</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">The output contains unescaped quotation marks, which makes the output invalid json.</p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">Quote marks should be escaped, for example:</p>
<div class="highlight highlight-source-json notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{&quot;[\&quot;bar\&quot;,\&quot;one\&quot;]&quot;:-0.0591166327,&quot;[\&quot;bar\&quot;,\&quot;two\&quot;]&quot;:0.871145093,&quot;[\&quot;baz\&quot;,\&quot;one\&quot;]&quot;:0.61280938,&quot;[\&quot;baz\&quot;,\&quot;two\&quot;]&quot;:0.3848564991,&quot;[\&quot;foo\&quot;,\&quot;one\&quot;]&quot;:-0.8986592304,&quot;[\&quot;foo\&quot;,\&quot;two\&quot;]&quot;:-0.4631529084,&quot;[\&quot;qux\&quot;,\&quot;one\&quot;]&quot;:-1.3482521044,&quot;[\&quot;qux\&quot;,\&quot;two\&quot;]&quot;:0.5209236198}"><pre class="notranslate">{<span class="pl-ent">"[<span class="pl-cce">\"</span>bar<span class="pl-cce">\"</span>,<span class="pl-cce">\"</span>one<span class="pl-cce">\"</span>]"</span>:<span class="pl-c1">-0.0591166327</span>,<span class="pl-ent">"[<span class="pl-cce">\"</span>bar<span class="pl-cce">\"</span>,<span class="pl-cce">\"</span>two<span class="pl-cce">\"</span>]"</span>:<span class="pl-c1">0.871145093</span>,<span class="pl-ent">"[<span class="pl-cce">\"</span>baz<span class="pl-cce">\"</span>,<span class="pl-cce">\"</span>one<span class="pl-cce">\"</span>]"</span>:<span class="pl-c1">0.61280938</span>,<span class="pl-ent">"[<span class="pl-cce">\"</span>baz<span class="pl-cce">\"</span>,<span class="pl-cce">\"</span>two<span class="pl-cce">\"</span>]"</span>:<span class="pl-c1">0.3848564991</span>,<span class="pl-ent">"[<span class="pl-cce">\"</span>foo<span class="pl-cce">\"</span>,<span class="pl-cce">\"</span>one<span class="pl-cce">\"</span>]"</span>:<span class="pl-c1">-0.8986592304</span>,<span class="pl-ent">"[<span class="pl-cce">\"</span>foo<span class="pl-cce">\"</span>,<span class="pl-cce">\"</span>two<span class="pl-cce">\"</span>]"</span>:<span class="pl-c1">-0.4631529084</span>,<span class="pl-ent">"[<span class="pl-cce">\"</span>qux<span class="pl-cce">\"</span>,<span class="pl-cce">\"</span>one<span class="pl-cce">\"</span>]"</span>:<span class="pl-c1">-1.3482521044</span>,<span class="pl-ent">"[<span class="pl-cce">\"</span>qux<span class="pl-cce">\"</span>,<span class="pl-cce">\"</span>two<span class="pl-cce">\"</span>]"</span>:<span class="pl-c1">0.5209236198</span>}</pre></div>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<p dir="auto">I reproduced it in pandas install from master:</p>
<details>
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
<p dir="auto">pandas: 0.19.0+401.g8452080<br>
nose: None<br>
pip: 9.0.1<br>
setuptools: 27.2.0<br>
Cython: 0.25.2<br>
numpy: 1.12.0<br>
scipy: None<br>
statsmodels: None<br>
xarray: None<br>
IPython: None<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.6.0<br>
pytz: 2016.10<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
feather: None<br>
matplotlib: None<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: None<br>
html5lib: None<br>
httplib2: None<br>
apiclient: None<br>
sqlalchemy: None<br>
pymysql: None<br>
psycopg2: None<br>
jinja2: None<br>
s3fs: None<br>
pandas_datareader: None</p>
</details>
<h4 dir="auto">Code Sample, a copy-pastable example if possible</h4>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import pandas as pd
import datetime

pd.read_json(pd.DataFrame(True, index=pd.date_range(datetime.date(2017, 1, 20), datetime.date(2017, 1, 23)), columns=['foo', 'bar']).stack().to_json())
"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-k">import</span> <span class="pl-s1">datetime</span>

<span class="pl-s1">pd</span>.<span class="pl-en">read_json</span>(<span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(<span class="pl-c1">True</span>, <span class="pl-s1">index</span><span class="pl-c1">=</span><span class="pl-s1">pd</span>.<span class="pl-en">date_range</span>(<span class="pl-s1">datetime</span>.<span class="pl-en">date</span>(<span class="pl-c1">2017</span>, <span class="pl-c1">1</span>, <span class="pl-c1">20</span>), <span class="pl-s1">datetime</span>.<span class="pl-en">date</span>(<span class="pl-c1">2017</span>, <span class="pl-c1">1</span>, <span class="pl-c1">23</span>)), <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'foo'</span>, <span class="pl-s">'bar'</span>]).<span class="pl-en">stack</span>().<span class="pl-en">to_json</span>())</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">The result of <code class="notranslate">pd.DataFrame(True, index=pd.date_range(datetime.date(2017, 1, 20), datetime.date(2017, 1, 23)), columns=['foo', 'bar']).stack().to_json()</code> contains</p>
<p dir="auto"><code class="notranslate">r'{"[1484870400000,"foo"]":true,"[1484870400000,"bar"]"'</code>,</p>
<h4 dir="auto">Expected Output</h4>
<p dir="auto">Whereas it should be:<br>
<code class="notranslate">r'{"[1484870400000,\"foo\"]":true,"[1484870400000,\"bar\"]"'</code></p>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 3.4.5.final.0
python-bits: 32
OS: Windows
machine: AMD64
LC_ALL: None
LANG: None
LOCALE: None.None
<p dir="auto">pandas: 0.19.1<br>
Cython: 0.25.1<br>
numpy: 1.11.2<br>
pandas_datareader: None</p>
</details>