How to ignore \ before " in simplejson?

74 views Asked by At

In python simplejson my dictionary is like

>>> s= {u'hello': u"Hi, i'm here"}
>>> simplejson.dumps(s)
'{"hello": "Hi, i\'m here"}'

But I want like

'{"hello": "Hi, i'm here"}'

How to do that?

2

There are 2 answers

5
aIKid On

What you're seeing is only an internal representation. Python keep it that way so it can escape the quote you're having there.

If you print it, it will appear like normal.

>>> import json
>>> s = '{"hello": "Hi, i\'m here"}'
>>> print(s)
{"hello": "Hi, i'm here"}
2
Eric On

Python is telling you the repr of the string - how to create the string with python syntax. If you want want to see the actual contents of the string, print it:

>>> s= {u'hello': u"Hi, i'm here"}
>>> print simplejson.dumps(s)
{"hello": "Hi, i'm here"}