Forum Discussion

arunsadhasivam's avatar
arunsadhasivam
New Contributor
6 years ago

Snaplogic iterate over array

Hi ,

i have json like
payload{
input:[
{url: "test.com’,}
{url: "test.com’,},
{url: "test.com’,}
]
}

i need to iterate over payload.input[0].url ,payload.input[1].url and send url to restPOST api.
can you please suggest anyoption to get individual url by iterate the url list

5 Replies

  • tstack's avatar
    tstack
    Former Employee

    I think you’re looking for the JSONSplitter snap. The Splitter will break up the array into multiple documents that you can feed into a REST POST snap. You’ll probably want to configure the Splitter with a path like $payload.input[*]. You can include parts of the original document in the documents output by the Splitter using the “Include scalar parents” and “Include paths” options.

    • arunsadhasivam's avatar
      arunsadhasivam
      New Contributor

      no i tried json-splitter but the thinhg is it is returning collection of url , i need one url from collection at a time and use that url should be in rest post . let me know any option. i need some thing like queue or forloop. i tried sequence which can generate a counter 1-n records but i could not keep iterate over it.
      i am new to snaplogic, i see only option is push to queue . but iam looking for some option other than this .

      • arunsadhasivam's avatar
        arunsadhasivam
        New Contributor

        let me know if any option i missed in json splitter which could allow loop over collection one at a time.

  • can you help me to understand rest post. can i send collections of url to rest post.
    please kindly send me any sample input message which can be accepted by REST POST snap.
    {
    “payload” : {
    “input” : [
    {
    “url” : “https://test.com/v1/leads/144307/merge.json?access_token=[TOKEN]&leadId=144436
    },
    {
    “url” : “https://test.com/v1/leads/144307/merge.json?access_token=[TOKEN]&leadId=144436
    },
    {
    “url” : “https://test.com/v1/leads/144307/merge.json?access_token=[TOKEN]&leadId=144436
    },
    ]
    }
    },

    Also let me know whether payload like below accepted or only it should be wrapped inside
    document like above.
    payload{
    [‘test.com’,
    test2.com’,
    test3.com
    ]
    }