Forward slash in json file from pandas dataframe
pandas
uses the ujson library under the hood to convert to json, and it seems that it escapes slashes - see issue here.
As a workaround, you could use the python standard library json
module to dump the data - it won't be as performant, but won't escape the slashes.
import json
json.dumps(df.values.tolist())
Out[248]: '[[1.0, "img/blue.png"], [2.5, "img/red.png"]]'
I'm not certain but I believe you want those. I think the forward slash will break your json and needs to be escaped. Have you verified that the added back slashes are an issue?
in the part where you are converting the pandas dataframe to json, if you will use loads
, it will escape the \
forward slashes
out = df.to_json(orient='values')[1:-1]
print out
try
import json
print json.dumps(json.loads(out))
for python 3:
import json
print(json.dumps(json.loads(out)))