Vignesh
Vignesh

Reputation: 1641

Backslash is added to JSON before double quote

As a json response I got it from server

{"Data":["{\"item1\": \"value1\",\"item2\": \"value2\"}"]}

I used

a=json.loads(response)
print(a)
self.write(a)

From terminal I saw

{u'Data':[u'{"item1": "value1", "item2": "value2"}"]'}

From postman it's like

{"Data":["{\"item1\": \"value1\",\"item2\": \"value2\"}"]}

I need as

{"Data":[{"item1": "value1","item2": "value2"}]}

I know all this format are right but I prefer the last format in postman. Thanks in advance

Upvotes: 1

Views: 3199

Answers (1)

Vignesh
Vignesh

Reputation: 1641

I tried the below and it works...

content = json.loads(content)['data']
temp = []
for values in content:
   jstr = json.loads(values)
   temp.append(jstr)
val = {"data": temp}
self.write(json.dumps(val))

Upvotes: 1

Related Questions