yooons
yooons

Reputation: 127

how can i Extract JSON from HTTP Response (python)

i get this from lambda api gateway. how can i get {\n "a":"b",\n "c":"d",\n "e":"f",\n "g":"h"\n} to json style ?

"------WebKitFormBoundarySfqiG2UABUZYF7Ir\r\n
Content-Disposition: form-data; 
name=\"upload-file\"; 
filename=\"example.json\"\r\n
Content-Type: application/json\r\n\r\n
{\n \"a\":\"b\",\n \"c\":\"d\",\n \"e\":\"f\",\n \"g\":\"h\"\n}
\r\n------WebKitFormBoundarySfqiG2UABUZYF7Ir--"

i want make this {\n "a":"b",\n "c":"d",\n "e":"f",\n "g":"h"\n}

to


{
  "a":"b",
  "c":"d",
  "e":"f",
  "g":"h"
}

Upvotes: 0

Views: 190

Answers (1)

Nguyen
Nguyen

Reputation: 96

How do you handle a response to get this?

Try this

import json
result = json.loads(x[x.find('{'): x.find('}')+1])

x is your string

Upvotes: 1

Related Questions