Is there a way to prevent pandas to_json from adding \?
<p>I am trying to send a pandas dataframe to_json and I am having some issues with the date.  I am getting an addtional \ so that my records look like <code>Updated:09\/06\/2016 03:09:44</code>.  Is it possible to not have this additional \ added?  I am assuming that it is an escape character of some sort but I haven't been able to find any additional information regarding this.</p>

<p>I have been adjusting the various parameters but I havent had any luck <code>df[0:10].to_json('splunkJsonFormat.txt', orient='records', date_format='ISO8601')</code></p>

<p>Sample Data:</p>

<pre><code>b_Updated,
Updated:09/06/2016 03:09:44,
Updated:06/29/2016 08:16:52,
Updated:09/07/2016 07:54:37,
</code></pre>

<p>The JSON ouput you obtained is indeed correct and is the right behavior.</p>

<p>Allowing <code>\/</code> helps when embedding JSON in a <code>&lt;script&gt;</code> tag, which doesn't allow <code>&lt;/</code> inside strings. Hence, in JSON <code>/</code> and <code>\/</code> are equivalent.</p>

<p>One workaround would be to separate the date from the string and convert it to a format more suitable where the datetime format is more evident.</p>

<pre><code>df['b_Updated'] = df['b_Updated'].str.split(':', 1)       \
                                 .apply(lambda x: x[0] + ':' + str(pd.to_datetime(x[1])))

df.to_json(orient='records', date_format='iso')

[{"b_Updated":"Updated:2016-09-06 03:09:44"},
 {"b_Updated":"Updated:2016-06-29 08:16:52"},
 {"b_Updated":"Updated:2016-09-07 07:54:37"}]
</code></pre>

python json pandas to-json