My JSON files looks like this
"{\"GetEventHeadlines_Response_1\":{\"EventHeadlines\":
{\"Headline\":[{\"CountryCode\":\"US\",\"EventType\":\"EarningsCallsAndPresentations\",
\"Duration\":
{\"EndDateTime\":\"2019-12-30T12:00:00\",\"EndQualifier\":\"None\", \"IsEstimate\":false,\"StartDateTime\":\
"2019-12-30T12:00:00\",\"StartQualifier\":
\"DateTime\"},\"EventId\":12969284......
I want to change this to
{
"GetEventHeadlines_Response_1":{
"EventHeadlines":{
"Headline":[
{
"CountryCode":"US",
"Duration":{
"EndDateTime":"2019-12-30T12:00:00",
"EndQualifier":"None",
"IsEstimate":false,
"StartDateTime":"2019-12-30T12:00:00",
"StartQualifier":"DateTime"
},
"EventId":12969284,.....
So in short i want to get rid of the ""(only at the beginning and end ) and the \\ sign.
import json
data = '''
{\"GetEventHeadlines_Response_1\":{\"EventHeadlines\":
{\"Headline\":[{\"CountryCode\":\"US\",\"EventType\":\"EarningsCallsAndPresentations\",
\"Duration\":
{\"EndDateTime\":\"2019-12-30T12:00:00\",\"EndQualifier\":\"None\", \"IsEstimate\":false,\"StartDateTime\":\
"2019-12-30T12:00:00\",\"StartQualifier\":
\"DateTime\"}
'''
data = json.loads(json.dumps(data))
print(data)
import json
myUnfomattedJSON = "..."
jsonObj = json.loads(myUnformattedJSON)
formattedJSON = json.dumps(jsonObj, indent=2)
print(formattedJSON)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.