Create new object at end of array
I have a flat file shown here:
“firstName”: “Gregor”
“lastName”: “Samsa”
“mainAddress”: “123 Main St”
“mainCity”: “Boston”
“mainState”: “MA”
“mainZip”: “02131”
“mailingAddress”: “456 Mailing Ave”
“mailingCity”: “Somerville”
“mailingState”: “MA”
“mailingZip”: “02144”
“shippingAddress”: “789 Shipping Blvd”
“shippingCity”: “Brookline”
“shippingState”: “MA”
“shippingZip”: “02122”
I am trying to break this out into an array of address objects split up by type using a mapper snap. The only way I have been successful so far is to hard-code the index in, like this:
$mailingCity >= $addresses.address[0].city
$shippingAddress >= $addresses.address[1].city
In the documentation for the mapper snap, there is a section that I thought would solve my issue using (value.length) in the index position. However, when I use (value.length) directly, or try inputting my array:
($addresses.address.length)
the snap fails. Has anyone done something like this before? The target schema looks like this:
“first_name”: “Gregor”
“last_name”: “Samsa”
“addresses”: [
{“address_type”: “main”,
“street_line_1”: “123 Main St”,
“city”: “Boston”,
“state”: “MA”,
“zip”: “02131”
},
{“address_type”: “mailing”,
“street_line_1”: “456 Mailing Ave”,
“city”: “Somerville”,
“state”: “MA”,
“zip”: “02144”
},
{"address_type’: “shipping”,
“street_line_1”: “789 Shipping Blvd”,
“city”: “Brookline”,
“state”: “MA”,
“zip”: “02122”
}
]
Thanks.