0

Requesting a REST-API with the python requests package I got a JSON-string that is full of Java-Escapes. E.g. it uses \u00f6 instead of ö. I could replace each escape-string with the respective character, but I suppose there are much better solutions.

Here is my code:

data = requests.get(url,auth=auth, headers=headers)
parsed = json.loads(data.content)
with open('data.json', 'w') as outfile:
  json.dump(parsed,outfile,indent=4,sort_keys=True)

There is a similar question answered here but i did not succeed trying to adapt it to my problem.

EDIT: This is a snippet of the output:

"address": {
    "quarter": "Niedersch\u00f6nhausen (Pankow)", 
    "street": "Blankenburger Stra\u00dfe", 
    "wgs84Coordinate": {
        "latitude": 52...., 
        "longitude": 13....
        }
}
dijea
  • 23
  • 4
  • This question could really use a [Minimal, Complete, and Verifiable](http://stackoverflow.com/help/mcve) example. That makes it easier for us to help you. In this case, showing the strings that are not what you expected could be helpful – Stephen Rauch Mar 03 '17 at 20:41
  • Thank you. I added a piece of the output. – dijea Mar 05 '17 at 20:50
  • It's not a "java-escape", it's a JSON syntax: http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf And it's a JSON parser responsibility to parse it accordingly. Any standard-compliant parser would just work fine http://ideone.com/ffmbmm – zerkms Mar 05 '17 at 20:51
  • So the string is exactly as expected from the `json.dumps()`. What is your use case? What do you need the output of `json.dumps()` to be used for? – Stephen Rauch Mar 05 '17 at 20:54
  • Ok, thank you for your quick responses! My purpose is to convert it to GeoJSON to display it on a webmap. So i suppose this won't be a problem with the JSON parser. By mistake i thought this encoding was an error. – dijea Mar 05 '17 at 21:04

0 Answers0