I'm trying to:
- import chunk of JSONS
- modify their dates from date time objects GMT+2 to unix in utc
- save them with the new date
According to this post, I've tried the following:
import os, json, pytz
from datetime import datetime, timezone
path_to_json = 'C:/Users/my_path/'
json_files = [pos_json for pos_json in os.listdir(path_to_json) if pos_json.endswith('.json')]
for js in json_files:
with open(os.path.join(path_to_json, js)) as json_file:
json_text = json.load(json_file)
json_text["startTime"].replace(tzinfo=timezone.utc)
However, I'm getting the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-191fccafcb88> in <module>()
8 with open(os.path.join(path_to_json, js)) as json_file:
9 json_text = json.load(json_file)
---> 10 json_text["startTime"].replace(tzinfo=timezone.utc)
TypeError: replace() takes no keyword arguments
Here's an example for a the JSON's structure:
json_text
{'eventsData':
[{'LeftHandColor': '00A72BFF',
'RightHandColor': '00A72BFF',
'Type': 7,
'UTCTime': 1533647793167.33},
{'LeftHandColor': None,
'RightHandColor': None,
'Type': 4,
'UTCTime': 1533647944567.94}],
'startTime': '2018-08-07T13:15:48.652076Z'}
Appreciate your help understanding what I'm doing wrong. Thanks