Skip to main content

Handling API property that can be Array or Object



  • Kelly Izer


       Try setting up branching where one branch has the array, and the other does not.


    This would also allow you to easily setup your mappings as you will have to configure the mappings to account for the array as well.

  • Steve Klett Strategic Partner
    Celigo University Level 4: Legendary
    Answer Pro
    Great Answer
    Top Contributor
    Awesome Follow-up

    Thanks for the reply Kelly. I'm concerned about the maintenance load of duplicating the import and mappings. I was hoping for a way to transform the singular object into an array, then mappings can treat it generically.

    I ended up doing this with a few lines of script in a pre Save Page script.

    //  We need to process the response from the API because if the order has 1 line, 
    // then SaleLines.SaleLine is an Object, if there are multiple lines, it's an Array.
    // Totally stupid of the API designer, but whatever. We need to homogenize the
    // response as Array so we can work with it in the rest of the flow. => {
      if (sale.sale_lines && Array.isArray(sale.sale_lines) === false) {
        console.log('Wrapping single line Object in Array')
        sale.sale_lines = [sale.sale_lines]

    I guess the feature request here is for transformation mapping to support array notation on source data and when it's a single object to still handle it. This would be very easy to support.

    The above script could be replaced with a transformation mapping like:

    record.sales_lines[*].fooBar ==> lines[*].fooBar

    If sales_lines is an {} it would still handle it fine and map to an array with single record on the transformation result.

  • Bas van Ditzhuijzen Strategic Partner NetSuite Integration Whiz Salesforce Integration Whiz
    Great Answer
    Answer Pro
    Celigo University Level 4: Legendary

    You can do this by adding both cases in the visual export transformation:

    This works because if its an array only the top mapping will map, if its an object only the bottom one will be used.

    I've used this before for an xml response that gets parsed to an object when there was only 1 entry. But yes it would be great if we could tell the parser what to always treat as an array.


Please sign in to leave a comment.