After using a JSON splitter and a filter, how do you put the object/array back together?

Hi, we needed to filter on a JSON input. We managed to get that working by using a JSON splitter on the element and then piping that to a filter snap. Our issue is now the input that looked like this:

        "allLocations": {
          "location": [
            {
              "addressInternalid": 2631363,
              "isDelete": false,
              "internalSupplierid": 3423589,
              "acctGrpid": "RT",
              "address1": "5309 GREENWAY",
              "address2": "5301 REDWAY",
              "address3": "5504 BLUEWAY",
              "poBox": "0912KHJWD",
              "country": "USA",
              "state": "US-TX",
              "city": "FREE",
              "zip": "78211",
              "phone": "2229808888",
              "phoneExtn": "091",
              "fax": "747",
              "faxExtn": "737"
            },
            {
              "addressInternalid": 2631367,
              "isDelete": false,
              "internalSupplierid": 3423589,
              "acctGrpid": "RT",
              "address1": "11305 4 PTS DR",
              "address2": "BLDG 2,#100",
              "country": "USA",
              "state": "US-TX",
              "city": "AUSTIN",
              "zip": "78726",
              "phone": "5126648805",
              "phoneExtn": "123",
              "fax": "123",
              "faxExtn": "134"
            },
            {
              "addressInternalid": 2631368,
              "isDelete": false,
              "internalSupplierid": 3423589,
              "acctGrpid": "RT",
              "address1": "REMIT 11305 4 PTS DR",
              "address2": "BLDG 3",
              "country": "USA",
              "state": "US-TX",
              "city": "AUSTIN",
              "zip": "78725",
              "phone": "5126600000",
              "phoneExtn": "678",
              "fax": "678",
              "faxExtn": "678"
            }
          ]
        },

Looks like this:

[
  {
    "addressInternalid": 2631363,
    "isDelete": false,
    "internalSupplierid": 3423589,
    "acctGrpid": "RT",
    "address1": "5309 GREENWAY",
    "address2": "5301 REDWAY",
    "address3": "5504 BLUEWAY",
    "poBox": "0912KHJWD",
    "country": "USA",
    "state": "US-TX",
    "city": "FREE",
    "zip": "78211",
    "phone": "2229808888",
    "phoneExtn": "091",
    "fax": "747",
    "faxExtn": "737",
    "fullCompanyName": "SUPPLIER MARCH 3 dba TEXT",
    "requestId": 5272423,
    "id": "3423589",
    "facilityCode": "0001",
    "systemCode": "1",
    "supplierType": "Operational",
    "status": "ACTIVE"
  },
  {
    "addressInternalid": 2631367,
    "isDelete": false,
    "internalSupplierid": 3423589,
    "acctGrpid": "RT",
    "address1": "11305 4 PTS DR",
    "address2": "BLDG 2,#100",
    "country": "USA",
    "state": "US-TX",
    "city": "AUSTIN",
    "zip": "78726",
    "phone": "5126648805",
    "phoneExtn": "123",
    "fax": "123",
    "faxExtn": "134",
    "fullCompanyName": "SUPPLIER MARCH 3 dba TEXT",
    "requestId": 5272423,
    "id": "3423589",
    "facilityCode": "0001",
    "systemCode": "1",
    "supplierType": "Operational",
    "status": "ACTIVE"
  },
  {
    "addressInternalid": 2631368,
    "isDelete": false,
    "internalSupplierid": 3423589,
    "acctGrpid": "RT",
    "address1": "REMIT 11305 4 PTS DR",
    "address2": "BLDG 3",
    "country": "USA",
    "state": "US-TX",
    "city": "AUSTIN",
    "zip": "78725",
    "phone": "5126600000",
    "phoneExtn": "678",
    "fax": "678",
    "faxExtn": "678",
    "fullCompanyName": "SUPPLIER MARCH 3 dba TEXT",
    "requestId": 5272423,
    "id": "3423589",
    "facilityCode": "0001",
    "systemCode": "1",
    "supplierType": "Operational",
    "status": "ACTIVE"
  }
]

How do I get it back into an object so I can map it correctly? As you can see in the below image, all of the location fields are coming in as strings with no hierarchy, not the array they were originally.

Any tips would be appreciated!

I think the GroupByN snap will do what you want. If you set the “Group Size” to zero, it will collect all of the input documents.

Another approach would be to use the expression language. You could call the filter() method on the array with a callback function that checks the condition. For example, if you wanted to filter the array by the state property, you could do something like this:

$allLocations.location.filter(elem => elem.state == "US-TX")
1 Like

Thanks! I’ll give that a try!