Hi,
I have a json and I would like to format all the date and time attribute to a specific format using python.
_result= [{"attributes":{"OBJECTID":objectid, "ATTRIBUTE1": A1 , "DATE1": "%Y-%m-%dT%H:%M:%SZ", "ATTRIBUTE3": A3,"DATE2": "%Y-%m-%dT%H:%M:%SZ", ... ,"ATTRIBUTEN": AN}}]
I would like to have
_result= [{"attributes":{"OBJECTID":objectid, "ATTRIBUTE1": A1 , "DATE1": "%Y-%m-%d %H:%M:%S", "ATTRIBUTE3": A3,"DATE2": "%Y-%m-%d %H:%M:%S", ... ,"ATTRIBUTEN": AN}}]
I tried this:
import datetime
import json
def formatting_date(feature):
array = json.loads(feature.getAttribute('_result'))
for m in array:
for k, v in m['attributes'].items():
if instance (v,datetime.dateime):
v=datetime.strptime(v,'%y-%m-%d %h:%m:%s')
feature.setAttribute('prop_', json.dumps(array))
but it failed.
Any suggestions?