Forum Discussion

jfpelletier's avatar
jfpelletier
Contributor
2 years ago
Solved

Converting an array to a JSON payload

Hello all,

I need to convert an array of ID values into a JSON payload, and I cannot find any array function that can iterate the values of the list to generate what I need.

My array of IDs looks like this: ["r4ige6rwgvnr", "4nkmdoijydfj9", "6ashbd99w3"]

The payload that I need is:

 

{
    "ids": [
        {
            "id": "r4ige6rwgvnr"
        },
        {
            "id": "4nkmdoijydfj9"
        },
        {
            "id": "6ashbd99w3"
        }
    ]
}

 

Is there a way (ideally built-in method) to iterate each ID from the array and generate the JSON format that I need?

Thanks a lot in advance!

JF

3 Replies

  • swright's avatar
    swright
    New Contributor III

    Hi Robin,

    I’m having some trouble getting it into that format. I’m using a union and somehow that is the output of the union. The target path of mapper2 is the $requestBody.ExternalIdentifierNumber and mapper3 is the $serviceUrl.:

    Thanks,

    Scott

    • robin's avatar
      robin
      Former Employee

      @swright A Union will combine two streams of documents into a single stream.

      What you want to do is combine the actual document contents themselves (a document in one stream is combined with the content of a document in another stream). To do this, use the Join Snap where the left and right paths resolve to the same constant value e.g.