0

I have the following issue: I am trying to execute the code:

import requests
import json
url = 'https://data.gov.gr/api/v1/query/mdg_emvolio?date_from=2021-01-07&date_to=2021-01-14'
headers = {'Authorization':'Token xxxxxxxxxxxxxx’}
response = requests.get(url, headers=headers)
json_object = json.loads(response.text)
json_formatted_str = json.dumps(json_object, indent=2)
print(json_formatted_str)

I want the output to be nice formatted in json, but the Greek characters do not appear correctly. I get the following output (a part of):

{
    "area": "\u0391\u0399\u03a4\u03a9\u039b\u039f\u0391\u039a\u0391\u03a1\u039d\u0391\u039d\u0399\u0391\u03a3",
    "areaid": 701,
    "daydiff": 10,
    "daytotal": 60,
    "referencedate": "2021-01-07T00:00:00",
    "totaldistinctpersons": 210,
    "totalvaccinations": 210
  },

On the other hand, if I use:

print (response.json())

I get correct Greek characters but (as expected), no nice as for example the following:

{'area': 'ΑΙΤΩΛΟΑΚΑΡΝΑΝΙΑΣ', 'areaid': 701, 'daydiff': 10, 'daytotal': 60, 'referencedate': '2021-01-07T00:00:00', 'totaldistinctpersons': 210, 'totalvaccinations': 210},

Any ideas?

Paradigm
  • 149
  • 1
  • 2
  • 10
  • 1
    `pprint.pprint(response.json())` see [`pprint` — Data pretty printer](https://docs.python.org/3/library/pprint.html)? – JosefZ Jan 14 '21 at 20:51
  • Does this answer your question? [How do I write JSON data to a file?](https://stackoverflow.com/questions/12309269/how-do-i-write-json-data-to-a-file) – JosefZ Jan 14 '21 at 21:51

1 Answers1

0

As suggested by JosefZ, I modified the code as follows:

import requests
import json
import pprint
url = 'https://data.gov.gr/api/v1/query/mdg_emvolio?date_from=2021-01-07&date_to=2021-01-14'
headers = {'Authorization':'Token xxxxxxxxxxxxxx’}
response = requests.get(url, headers=headers)
pprint.pprint(response.json()) 
Paradigm
  • 149
  • 1
  • 2
  • 10