Skip to content

jslt for loop capability #191

Answered by larsga
brh asked this question in Q&A
May 5, 2021 · 2 comments · 5 replies
Discussion options

You must be logged in to vote

Given this input:

{"cartId": "6795708823149918171",
"cartItems": [ {
  "fulfillments": [ {"fulfillmentType": "PARCEL"},
                    {"fulfillmentType": "PICKUP"},
                    {"fulfillmentType": "TRUCK"}]},
  {
  "fulfillments": [ {"fulfillmentType": "OTHER"}]}
],
"createdOn": "2021-05-05T15:09:14Z"
}

you can get the output you want with:

let tmp = flatten([for(.cartItems) .fulfillments])

{"&&events" : join([for ($tmp) "xxx=" + .fulfillmentType], ";")}

Having to use flatten and multiple for loops is not really ideal, so I think we do need to add an array traversal operator (already planned in issue #183).

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@larsga
Comment options

@brh
Comment options

@larsga
Comment options

@brh
Comment options

Comment options

You must be logged in to vote
1 reply
@brh
Comment options

Answer selected by brh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants