我需要在JSON响应上添加键值格式的时间戳。这就是我现在所拥有的:
now = datetime.datetime.now().isoformat(sep=" ", timespec="seconds")
result = session.get(urljoin(baseurl, path), headers=headers, params=querystring, verify=False)
jsonarray = result.json()
json_object = json.dumps(jsonarray)
#writing to ruletrees.json
with open("/opt/bamboo/logs/outputfile", "a") as outfile:
outfile.write(now + json_object + "
")
当前输出如下
2023-06-26 12:41:49{"account": "act_F-AC-1234", "contract": "ctr_F-1234"}
2023-06-26 12:42:49{"account": "act_F-AC-5678", "contract": "ctr_F-5678"}
我想要的输出应该是(用括号括起来)
{"date_time":"2023-06-26 12:41:49"{"account": "act_F-AC-1234", "contract": "ctr_F-1234"}}
{"date_time":"2023-06-26 12:42:49"{"account": "act_F-AC-5678", "contract": "ctr_F-5678"}}
提前感谢