Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Backslash from JSON string?

I am using python url library to get json response from spatial reference website.This is my code. I get response_read="u'{\'type\': \'EPSG\', \'properties\': {\'code\': 102646}}'" but i need this response in this form:"{'type': 'EPSG', 'properties': {'code': 102646}}". How i achieve output in this form?

headers = {'User-Agent': 'Mozilla/5.0'}
 req = urllib2.Request("http://spatialreference.org/ref/esri/"nad-1983-stateplane-california-vi-fips-0406-feet"/json/", None, headers)
        response = urllib2.urlopen(req)
        response_read = response.read().decode('utf-8')
        result = json.dumps(response_read)  
        epsg_json = json.loads(result)
        epsg_code = epsg_json['properties']['code']
        return epsg_code
like image 243
Salman Ahmed Avatar asked Jul 19 '17 14:07

Salman Ahmed


People also ask

How do you remove backslash from string?

Use the String. replaceAll() method to remove all backslashes from a string, e.g. str. replaceAll('\\', '') . The replaceAll() method will remove all backslashes from the string by replacing them with empty strings.

How do I remove backslash from JSON string in Python?

Using replace() Function Along with The json. Loads() Function to Remove Backslash from Json String in Python.

How remove slashes from JSON in Java?

String jsonFormattedString = jsonStr. replaceAll("\\", "");


1 Answers

you need to first use dumps then loads

json_data = json.dumps(response_read)
json_without_slash = json.loads(json_data)
like image 117
Pranav Tripathi Avatar answered Nov 15 '22 11:11

Pranav Tripathi