02-08-2018 03:41 PM
I have JSON data from Workday with potentially many Phone_Data sections like below:
"Phone_Data" : [
{
"Formatted_Phone" : "XXXXXXXX",
"Phone_Device_Type_Reference" : {
"ID" : {
"Phone_Device_Type_ID" : "Telephone"
}
},
"Usage_Data" : [
{
"Public" : "1",
"Type_Data" : [
{
"Primary" : "1",
"Type_Reference" : {
"ID" : {
"Communication_Usage_Type_ID" : "WORK"
}
}
}
]
}
]
}
]
I have it getting the “first” WORK Formatted_Phone with code like below:
jsonPath($, "$Worker_Data.Personal_Data.Contact_Data.Phone_Data[?(value.Usage_Data[0].Type_Data[0].Type_Reference.ID.Communication_Usage_Type_ID == 'WORK')].Formatted_Phone")[0]
But I want the one where Primary==1 too…
I’ve played around a bit trying to put more conditions in there, but always end up with various errors. I’m pretty good with this kind of thing using XPATH with XML, but this is eluding me with JSON.
Any help is much appreciated!
02-09-2018 01:56 PM
Thanks to a little insider help, I was able to get this working, and figured I would share in case it might be useful to others. Below is the code I ended up using.
jsonPath($Worker_Data.Personal_Data.Contact_Data, "$Phone_Data[?(@.Usage_Data[0].Type_Data[0].Type_Reference.ID.Communication_Usage_Type_ID == 'WORK' && @.Usage_Data[0].Type_Data[0].Primary == '1')].Formatted_Phone")[0]
02-25-2019 11:58 AM
Ha, worked this out on my own not long ago, wish I had read this first, would have saved me some time!