Forum Discussion

christwr's avatar
christwr
Contributor III
8 years ago

JSON Query - Workday =/

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!

2 Replies

  • christwr's avatar
    christwr
    Contributor III

    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]

    • epearson's avatar
      epearson
      New Contributor III

      Ha, worked this out on my own not long ago, wish I had read this first, would have saved me some time!