<p dir="auto"><a href="https://github.com/hupili/pandas-to-json-multi-index-issue/blob/master/pandas%20to_json%20test.ipynb">https://github.com/hupili/pandas-to-json-multi-index-issue/blob/master/pandas%20to_json%20test.ipynb</a></p>
<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="
df = pd.DataFrame(
    [
        ['1', '2', 'a'],
        ['1', '3', 'b'],
        ['2', '4', 'c'],
        ['3', '5', 'd']
    ],
    columns=['key1', 'key2', 'key3']
)
j = df.set_index(['key1', 'key2']).to_json()
json.loads(j)
"><pre class="notranslate"><span class="pl-s1">df</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-v">DataFrame</span>(
    [
        [<span class="pl-s">'1'</span>, <span class="pl-s">'2'</span>, <span class="pl-s">'a'</span>],
        [<span class="pl-s">'1'</span>, <span class="pl-s">'3'</span>, <span class="pl-s">'b'</span>],
        [<span class="pl-s">'2'</span>, <span class="pl-s">'4'</span>, <span class="pl-s">'c'</span>],
        [<span class="pl-s">'3'</span>, <span class="pl-s">'5'</span>, <span class="pl-s">'d'</span>]
    ],
    <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'key1'</span>, <span class="pl-s">'key2'</span>, <span class="pl-s">'key3'</span>]
)
<span class="pl-s1">j</span> <span class="pl-c1">=</span> <span class="pl-s1">df</span>.<span class="pl-en">set_index</span>([<span class="pl-s">'key1'</span>, <span class="pl-s">'key2'</span>]).<span class="pl-en">to_json</span>()
<span class="pl-s1">json</span>.<span class="pl-en">loads</span>(<span class="pl-s1">j</span>)</pre></div>
<h4 dir="auto">Problem description</h4>
<p dir="auto">The exported JSON is ill-formatted</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
&lt;ipython-input-8-5f4db1ed154c&gt; in &lt;module&gt;()
----&gt; 1 json.loads(j)

/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    317             parse_int is None and parse_float is None and
    318             parse_constant is None and object_pairs_hook is None and not kw):
--&gt; 319         return _default_decoder.decode(s)
    320     if cls is None:
    321         cls = JSONDecoder

/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py in decode(self, s, _w)
    337 
    338         &quot;&quot;&quot;
--&gt; 339         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    340         end = _w(s, end).end()
    341         if end != len(s):

/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py in raw_decode(self, s, idx)
    353         &quot;&quot;&quot;
    354         try:
--&gt; 355             obj, end = self.scan_once(s, idx)
    356         except StopIteration as err:
    357             raise JSONDecodeError(&quot;Expecting value&quot;, s, err.value) from None

JSONDecodeError: Expecting ':' delimiter: line 1 column 13 (char 12)
"><pre class="notranslate"><code class="notranslate">---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
&lt;ipython-input-8-5f4db1ed154c&gt; in &lt;module&gt;()
----&gt; 1 json.loads(j)

/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    317             parse_int is None and parse_float is None and
    318             parse_constant is None and object_pairs_hook is None and not kw):
--&gt; 319         return _default_decoder.decode(s)
    320     if cls is None:
    321         cls = JSONDecoder

/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py in decode(self, s, _w)
    337 
    338         """
--&gt; 339         obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    340         end = _w(s, end).end()
    341         if end != len(s):

/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py in raw_decode(self, s, idx)
    353         """
    354         try:
--&gt; 355             obj, end = self.scan_once(s, idx)
    356         except StopIteration as err:
    357             raise JSONDecodeError("Expecting value", s, err.value) from None

JSONDecodeError: Expecting ':' delimiter: line 1 column 13 (char 12)

</code></pre></div>
<h4 dir="auto">Expected Output</h4>
<h4 dir="auto">Output of <code class="notranslate">pd.show_versions()</code></h4>
<details>
INSTALLED VERSIONS
------------------
commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Darwin
OS-release: 16.1.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
<p dir="auto">pandas: 0.18.1<br>
nose: 1.3.7<br>
pip: 7.1.2<br>
setuptools: 28.6.1<br>
Cython: None<br>
numpy: 1.11.2<br>
scipy: 0.18.1<br>
statsmodels: None<br>
xarray: None<br>
IPython: 5.1.0<br>
sphinx: None<br>
patsy: None<br>
dateutil: 2.5.3<br>
pytz: 2016.7<br>
blosc: None<br>
bottleneck: None<br>
tables: None<br>
numexpr: None<br>
matplotlib: 1.4.3<br>
openpyxl: None<br>
xlrd: None<br>
xlwt: None<br>
xlsxwriter: None<br>
lxml: None<br>
bs4: 4.5.1<br>
html5lib: None<br>
httplib2: 0.9.2<br>
apiclient: 1.5.4<br>
sqlalchemy: 1.1.2<br>
pymysql: None<br>
psycopg2: 2.6.2 (dt dec pq3 ext lo64)<br>
jinja2: 2.8<br>
boto: 2.43.0<br>
pandas_datareader: None<br>
In [4]:</p>
</details>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/Komnomnomnom/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/Komnomnomnom">@Komnomnomnom</a></p>
<p dir="auto">I'm using a recent anaconda build on Windows, which includes v 0.12.0 pandas.  I'm attempting to use a multi-index header, write it out to a json file, import it and get the same formatted dataframe.  The column headers come out stacked vertically instead.</p>
<p dir="auto">import numpy as np<br>
import pandas as pd<br>
pd.set_option('html',False)</p>
<p dir="auto">index = pd.MultiIndex(levels=[['foo', 'bar', 'baz', 'qux'],<br>
['one', 'two', 'three']],<br>
labels=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3],<br>
[0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],<br>
names=['foo', 'bar'])<br>
df = pd.DataFrame(np.random.randn(10, 3), index=index,<br>
columns=['A', 'B', 'C'])<br>
dft = df.transpose()<br>
dft<br>
dft.to_json('D:\xxmt.json',orient='split')<br>
dftj=pd.read_json('D:\xxmt.json',orient='split')<br>
dftj</p>