Integration Studio - Filtering a JSON (SMAX 24.1)

 In Integration Studio I'm having a syntax issue trying to filter a json to extract an element. In the sample json below, abbreviated for simplicity, I need to extract the endDate where the entitlementType=='INITIAL' && serviceLevelCode=='ND'.

I had thought this would work (and tried quite a few other variations): filter(json_parser(response.data,'$.result.entitlements'),'item.entitlementType=="EXTENDED" && item.ServiceLevelCode=="ND"','{"EndDt":item.endDate}',0)

But it does not extract the element.  Other, unfiltered elements are coming out fine.  What's wrong with my syntax? 

Thanks in advance, 

Lyn

  "code": 0,
  "originalCode": 200,
  "localChannel": "47",
  "countryCode":"US",

  "result": [
    {
      "id": 2137399848,
      "entitlements": [
        {

          "itemNumber": "1gj",
          "endDate": "2025-07-24T04:59:59.000001Z",
          "entitlementType": "INITIAL",
          "serviceLevelCode": "ND"
         },
        {
           "itemNumber": "2rb",
           "endDate": "2025-07-24T04:59:59.000001Z",
           "entitlementType": "INITIAL",
           "serviceLevelCode": "RR"
        },
        {
          "itemNumber": "3a",
          "endDate": "2028-07-24T04:59:59.000001Z",
          "entitlementType": "EXTENDED",
          "serviceLevelCode": "ND"
        }
      ]
    }
  ]
}

Parents
  • Verified Answer

    +1  

    Hi  

    According to the JSON item you provided

    the result and entitlements both are arrays

    Which element of the result array to use is not specified

    filter(json_parser(response.data,'$.result.entitlements'),'item.entitlementType=="EXTENDED" && item.ServiceLevelCode=="ND"','{"EndDt":item.endDate}',0)

    Could you please replace it with the below text and test it?

    filter(json_parser(response.data,'$.result[0].entitlements'),'item.entitlementType=="EXTENDED" && item.ServiceLevelCode=="ND"','{"EndDt":item.endDate}',0)

Reply
  • Verified Answer

    +1  

    Hi  

    According to the JSON item you provided

    the result and entitlements both are arrays

    Which element of the result array to use is not specified

    filter(json_parser(response.data,'$.result.entitlements'),'item.entitlementType=="EXTENDED" && item.ServiceLevelCode=="ND"','{"EndDt":item.endDate}',0)

    Could you please replace it with the below text and test it?

    filter(json_parser(response.data,'$.result[0].entitlements'),'item.entitlementType=="EXTENDED" && item.ServiceLevelCode=="ND"','{"EndDt":item.endDate}',0)

Children
  • 0 in reply to   

    Thanks very much!  That was really really close... 

    filter(json_parser(response.data,'$.result[0].entitlements'),'item.entitlementType=="EXTENDED" && item.serviceLevelCode=="ND"','{"EndDt":item.endDate}',0)

    returned execution details:

    {"expression":"filter(json_parser(response.data,'$.result[0].entitlements'),'item.entitlementType==\"EXTENDED\" && item.serviceLevelCode==\"ND\"','{\"EndDt\":item.endDate}',0);","result":"null"}

    I then tried changing result[0] to [0]

    filter(json_parser(response.data,'$.result[0].entitlements'),'item.entitlementType=="EXTENDED" && item.serviceLevelCode=="ND"','{"EndDt":item.endDate}',0)

    returned execution details: 

    {"expression":"filter(json_parser(response.data,'$.[0].entitlements'),'item.entitlementType==\"EXTENDED\" && item.serviceLevelCode==\"ND\"','{\"EndDt\":item.endDate}',0);","result":[{"EndDt":"2027-10-03T04:59:59.000001Z"}]}

    Great!!!!  Thanks very much! 

    One follow on question, if you care to answer it.....how would I get it to just respond with a result of "2027-10-03T04:59:59.000001Z" (no array, no header.) I tried to remove the EndDt: from the expression but that was not successful.

    Regards,

    Lyn