the code
import json
jsonData = {
'url' : 'test/file.jpg'
}
arrayData = json.dumps(jsonData)
# load the json to a string
resp = json.loads(arrayData)
resp['url'] = resp['url'].replace(r'/',r'\/')
print('without JSON output:',resp['url'])
jsonDataNew = [
{'url' : str(resp['url'])}
]
json_data = json.dumps(jsonDataNew)
json_data = json.loads(json_data)
print('with JSON output')
print(json_data)
the output
without JSON output: test\/file.jpg
with JSON output
[{'url': 'test\\/file.jpg'}]
the desired output would be
with JSON output
[{'url': 'test\/file.jpg'}]
no matter how, im not able to remove the escape in the JSON output, even converted into JSON file. is this something unavoidable in Python?
json_data[0]['url']at the end, I do get test\/file.jpg as expected.json.loads('[{"url": "test\/file.jpg"}]')totally works too.