There is a service and there is a base. It is necessary to check that the service receives the same that the base gives. From the service by a GET request I get JSON. But from the base here is:

(datetime.date(2019, 3, 18), 20) (datetime.date(2019, 3, 19), 20) (datetime.date(2019, 3, 20), 20) (datetime.date(2019, 3, 21), 20) 

How do i decode this in json?

Code:

 r = requests.get(url) recv = r.content.decode('utf-8') print(r.status_code) print(recv) print("Opened database successfully") cursor = conn.cursor() cursor.execute("select.......") record = cursor.fetchall() for dat in record: print(dat) 

1 answer 1

In this question on the English-language SO are presented more or less elegant ways to serialize date / datetime in JSON.

Here is one of the shortest options:

 In [89]: print(json.dumps(items, indent=2, default=str)) [ [ "2019-03-18", 20 ], [ "2019-03-19", 20 ], [ "2019-03-20", 20 ], [ "2019-03-21", 20 ] ]