I have a json pull using api and below is what the file looks like:
[
{
"id": 181,
"emp_number": "527",
"clock_id": "124",
"organization_trackings": [
{
"title": "Division",
"value": "200",
"value_description": "Cons"
},
{
"title": "Location",
"value": "951",
"value_description": "Jasp"
},
{
"title": "Special",
"value": "20",
"value_description": "Remote"
},
{
"title": "Primary Department",
"value": "200",
"value_description": "DPT1"
},
{
"title": "Secondary Department",
"value": "2000",
"value_description": "DH"
},
{
"title": "Function",
"value": "0000",
"value_description": "Resource"
}
]
},
{
"id": 181837,
"emp_number": "649",
"timeclock_id": "528",
"organization_trackings": [
{
"title": "Division",
"value": "200",
"value_description": "Consultant"
},
{
"title": "Location",
"value": "001",
"value_description": "Atlanta"
},
{
"title": "Function",
"value": "0000",
"value_description": "Resource"
}
]
}
]
I need to convert this to 2 csv files
first csv fileis:
id emp_number clock_id
181 527 124
181837 649 528
second csv file:
emp_number,title,value,value_description
527,Location,951,Jasp
527,Special,20,Remote
527,Primary Department,200,DPT1
527,Secondary Department,2000,DH
527,Function,0,Resource
649,Division,200,Consultant
649,Location,1,Atlanta
649,Function,0,Resource
I am new to python, can someone direct me how I can do it in python..?
2
Answers
I guess the key
"timeclock_id": "528"
is a typo and should be"clock_id": "528"
.Try:
Prints:
this checks for
clock_id
and if that fails checks fortimeclock_id
.working sample: https://onlinegdb.com/WaR32RLl2