<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Transform query result to nested list / nested json with multiple levels in Workato Pros Discussion Board</title>
    <link>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9589#M3908</link>
    <description>&lt;P&gt;&lt;a href="https://systematic.workato.com/t5/user/viewprofilepage/user-id/10358"&gt;@mlamotte&lt;/a&gt;&amp;nbsp;this is an old post but I figured I would give it a shot anyways. You've probably already solved this a long time ago, but here is the Ruby script to merge your data. The casing might be a bit off, but it works.&lt;/P&gt;&lt;P&gt;&lt;a href="https://systematic.workato.com/t5/user/viewprofilepage/user-id/11670"&gt;@andreasFe&lt;/a&gt;&amp;nbsp; I'm not exactly sure what you mean, but if you need to pass a list/array or object into an Ruby/JS/Python action, you can turn your input field to formula mode and simply drop in the data pill.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;## THE MERGINATOR ##

transportOrders = input["orders"]

to_group = transportOrders.group_by{ | t | t["transportOrder"]}.map{ | to_key, to_array |
  
  ## beginning of object
  { 
    "transportorder": to_key,
    "to_params": {
      "TO_param1": to_array[0]["to_param1"], ## this is lazy but works 
      "TO_param2": to_array[0]["to_param2"]  ## also lazy
    },
    "orders": to_array.group_by{|to|to["orderNumber"]}.map{ | order_key, order_array | 
      
      {
        "ordernumber": order_key,
        "order_params": {
          "Order_param1": order_array.find{|order| order["orderNumber"] == order_key}&amp;amp;.dig("order_param1"),
          "Order_param2": order_array.find{|order| order["orderNumber"] == order_key}&amp;amp;.dig("order_param2")
        },
        "orderitems": order_array.group_by{|order| order["orderItem"]}.map{ | item_key, item_array |
          {
            "Orderitem": item_key,
            "Orderitem_param1": item_array.find{|item| item["orderItem"] == item_key}&amp;amp;.dig("orderItem_param1"),
            "Orderitem_param2": item_array.find{|item| item["orderItem"] == item_key}&amp;amp;.dig("orderItem_param2")
          }
        }
      }
    }
  }
  ## end of object
}


{
  to_group: to_group
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Apr 2025 21:25:58 GMT</pubDate>
    <dc:creator>gary1</dc:creator>
    <dc:date>2025-04-10T21:25:58Z</dc:date>
    <item>
      <title>Transform query result to nested list / nested json with multiple levels</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/6771#M2919</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;I need to create a nested json based on a SQL query.&lt;/P&gt;&lt;P&gt;Sample dataset:&lt;/P&gt;&lt;P&gt;Transportorder TO_param1 TO_param2 Ordernumber Order_param1 Order_param2 Orderitem Orderitem_param1&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;OR-444450&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;CO-12345&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;CO-12345-1&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;OR-444450&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;CO-12345&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;CO-12345-2&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;OR-444450&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;CO-12346&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;CO-12346-1&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;OR-444451&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;CO-12400&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;CO-12400-1&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;OR-444451&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;CO-12400&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;CO-12400-2&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;OR-444452&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;CO-12405&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;TD&gt;y&lt;/TD&gt;&lt;TD&gt;CO-12405-1&lt;/TD&gt;&lt;TD&gt;x&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A transportOrder might either contain 1 or more Ordernumbers.&lt;BR /&gt;Each Ordernumber might container 1 or more OrderItems.&lt;/P&gt;&lt;P&gt;I need to nest them into a list and use this list for a HTTP POST request in json.&lt;/P&gt;&lt;P&gt;The output should look a bit like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
                      {
                        "transportorder": "OR-444450",
                        "to_params": {
                          "TO_param1": "x",
                          "TO_param2": "y"
                        },
                        "orders": [
                          {
                            "ordernumber": "CO-12345",
                            "order_params": {
                              "Order_param1": "x",
                              "Order_param2": "y"
                            },
                            "orderitems": [
                              {
                                "Orderitem": "CO-12345-1",
                                "Orderitem_param1": "x",
                                "Orderitem_param2": "y"
                              },
                              {
                                "Orderitem": "CO-12345-2",
                                "Orderitem_param1": "x",
                                "Orderitem_param2": "y"
                              }
                            ]
                          },
                          {
                            "ordernumber": "CO-12346",
                            "order_params": {
                              "Order_param1": "x",
                              "Order_param2": "y"
                            },
                            "orderitems": [
                              {
                                "Orderitem": "CO-12346-1",
                                "Orderitem_param1": "x",
                                "Orderitem_param2": "y"
                              }
                            ]
                          }
                        ]
                      },
                      {
                        "transportorder": "OR-444451",
                        "to_params": {
                          "TO_param1": "x",
                          "TO_param2": "y"
                        },
                        "orders": [
                          {
                            "ordernumber": "CO-12400",
                            "order_params": {
                              "Order_param1": "x",
                              "Order_param2": "y"
                            },
                            "orderitems": [
                              {
                                "Orderitem": "CO-12400-1",
                                "Orderitem_param1": "x",
                                "Orderitem_param2": "y"
                              },
                              {
                                "Orderitem": "CO-12400-2",
                                "Orderitem_param1": "x",
                                "Orderitem_param2": "y"
                              }
                            ]
                          }
                        ]
                      },
                      {
                        "transportorder": "OR-444452",
                        "to_params": {
                          "TO_param1": "x",
                          "TO_param2": "y"
                        },
                        "orders": [
                          {
                            "ordernumber": "CO-12405",
                            "order_params": {
                              "Order_param1": "x",
                              "Order_param2": "y"
                            },
                            "orderitems": [
                              {
                                "Orderitem": "CO-12405-1",
                                "Orderitem_param1": "x",
                                "Orderitem_param2": "y"
                              }
                            ]
                          }
                        ]
                      }
                    ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using 1 list where I enter the formatting using a json sample. But the issue stays the same, that I have to be able to loop over each TransportOrder, get the necessary information added to the list, then loop over the Ordernumbers, get the relevant information into the list, and then go deeper to OrderItems and get the relevant information.&lt;/P&gt;&lt;P&gt;The first issue with a for each is that there might be multiple lines with 1 unique Transportnumber. So I can't use this entire dataset as my source for the For Each. This would mean that I would need to do at least 3 SQL queries. But I just can't seem to fix it.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;In python it's much easier, as I am able to use a Dict, check if the TransportNumber is already in the dict, if not append.&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2024 09:27:32 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/6771#M2919</guid>
      <dc:creator>mlamotte</dc:creator>
      <dc:date>2024-05-28T09:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Transform query result to nested list / nested json with multiple levels</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/6774#M2922</link>
      <description>&lt;P&gt;I would stick with Python or Ruby. Doing this with loops could require a lot of tasks depending on the size of input.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2024 17:32:50 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/6774#M2922</guid>
      <dc:creator>gary1</dc:creator>
      <dc:date>2024-05-28T17:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: Transform query result to nested list / nested json with multiple levels</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/6775#M2923</link>
      <description>&lt;P&gt;That's what I was afraid of.&lt;/P&gt;&lt;P&gt;Well, for me it doesn't matter, it's that I'm the only one in my team with adequate knowledge of python.&lt;BR /&gt;&lt;BR /&gt;Thanks for the feedback!&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2024 06:10:33 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/6775#M2923</guid>
      <dc:creator>mlamotte</dc:creator>
      <dc:date>2024-05-29T06:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Transform query result to nested list / nested json with multiple levels</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/6776#M2924</link>
      <description>&lt;P&gt;I'm having some difficulties with the Python snippet in Workato.&lt;BR /&gt;How could I pass the entire query result as an array into Python?&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2024 06:39:11 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/6776#M2924</guid>
      <dc:creator>mlamotte</dc:creator>
      <dc:date>2024-05-29T06:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: Transform query result to nested list / nested json with multiple levels</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9588#M3907</link>
      <description>&lt;P&gt;I have the very same question. Passing an entire query result as input to Python/Ruby doesn't seem possible out of the box?&lt;BR /&gt;&lt;a href="https://systematic.workato.com/t5/user/viewprofilepage/user-id/1188"&gt;@gary1&lt;/a&gt;- any idea how that could be solved?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Apr 2025 15:45:48 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9588#M3907</guid>
      <dc:creator>andreasFe</dc:creator>
      <dc:date>2025-04-10T15:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Transform query result to nested list / nested json with multiple levels</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9589#M3908</link>
      <description>&lt;P&gt;&lt;a href="https://systematic.workato.com/t5/user/viewprofilepage/user-id/10358"&gt;@mlamotte&lt;/a&gt;&amp;nbsp;this is an old post but I figured I would give it a shot anyways. You've probably already solved this a long time ago, but here is the Ruby script to merge your data. The casing might be a bit off, but it works.&lt;/P&gt;&lt;P&gt;&lt;a href="https://systematic.workato.com/t5/user/viewprofilepage/user-id/11670"&gt;@andreasFe&lt;/a&gt;&amp;nbsp; I'm not exactly sure what you mean, but if you need to pass a list/array or object into an Ruby/JS/Python action, you can turn your input field to formula mode and simply drop in the data pill.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;## THE MERGINATOR ##

transportOrders = input["orders"]

to_group = transportOrders.group_by{ | t | t["transportOrder"]}.map{ | to_key, to_array |
  
  ## beginning of object
  { 
    "transportorder": to_key,
    "to_params": {
      "TO_param1": to_array[0]["to_param1"], ## this is lazy but works 
      "TO_param2": to_array[0]["to_param2"]  ## also lazy
    },
    "orders": to_array.group_by{|to|to["orderNumber"]}.map{ | order_key, order_array | 
      
      {
        "ordernumber": order_key,
        "order_params": {
          "Order_param1": order_array.find{|order| order["orderNumber"] == order_key}&amp;amp;.dig("order_param1"),
          "Order_param2": order_array.find{|order| order["orderNumber"] == order_key}&amp;amp;.dig("order_param2")
        },
        "orderitems": order_array.group_by{|order| order["orderItem"]}.map{ | item_key, item_array |
          {
            "Orderitem": item_key,
            "Orderitem_param1": item_array.find{|item| item["orderItem"] == item_key}&amp;amp;.dig("orderItem_param1"),
            "Orderitem_param2": item_array.find{|item| item["orderItem"] == item_key}&amp;amp;.dig("orderItem_param2")
          }
        }
      }
    }
  }
  ## end of object
}


{
  to_group: to_group
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Apr 2025 21:25:58 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9589#M3908</guid>
      <dc:creator>gary1</dc:creator>
      <dc:date>2025-04-10T21:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: Transform query result to nested list / nested json with multiple levels</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9596#M3913</link>
      <description>&lt;P&gt;Our question is why it's not possible to pass the "entire query result" / the rows of an SQL query into a python/ruby action.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-04-11_100219_redacted.png" style="width: 999px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/1994i9606C9AE4FCEAD20/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="Screenshot 2025-04-11_100219_redacted.png" alt="Screenshot 2025-04-11_100219_redacted.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;neither for list nor object inputs the "rows" pill is selectable.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 08:23:53 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9596#M3913</guid>
      <dc:creator>andreasFe</dc:creator>
      <dc:date>2025-04-11T08:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: Transform query result to nested list / nested json with multiple levels</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9614#M3915</link>
      <description>&lt;P&gt;Ah, this is a silly Workato thing. Define your input field as a &lt;STRONG&gt;string&lt;/STRONG&gt; and set it to formula mode. This will allow you to pass an object or array data pill. In your example, you have your inputs defined as a list and object, and while that may seem intuitive it will not work the way you expect it to.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 15:47:56 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9614#M3915</guid>
      <dc:creator>gary1</dc:creator>
      <dc:date>2025-04-11T15:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: Transform query result to nested list / nested json with multiple levels</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9616#M3917</link>
      <description>&lt;P&gt;Thanks for the reply!&lt;BR /&gt;I tried List/Object as String doesn't work either.&lt;BR /&gt;I (just like mlamotte) am not trying to pass a single value (equipment_id, article_number, ..) - but the whole rows-result-set. I don't think i can define that its a single "string" of rows coming back from the databse.. or am I missing something?&lt;/P&gt;&lt;P&gt;In general I'm trying to work around another issue that I posted here: &lt;A href="https://systematic.workato.com/t5/workato-pros-discussion-board/pass-through-json-quot-string-quot-from-database-query/m-p/9615#M3916" target="_blank" rel="noopener"&gt;https://systematic.workato.com/t5/workato-pros-discussion-board/pass-through-json-quot-string-quot-from-database-query/m-p/9615#M3916.&lt;/A&gt;&lt;BR /&gt;If you gave it a look, too that would be brilliant &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 16:01:54 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9616#M3917</guid>
      <dc:creator>andreasFe</dc:creator>
      <dc:date>2025-04-11T16:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: Transform query result to nested list / nested json with multiple levels</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9619#M3919</link>
      <description>&lt;P&gt;I know exactly what you mean, but maybe my explanation wasn't clear.&lt;/P&gt;&lt;P&gt;The "a_string_field" field is a string field set to formula mode. Once it's in formula mode, I'm able to pass the "blah blah blah" list as input.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="objec.jpg" style="width: 999px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/2007i0D878CAB29AAC08E/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="objec.jpg" alt="objec.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And just to really drive this home, here are the settings for "a_string_field":&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="string.jpg" style="width: 999px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/2008iE293C05EAF12393D/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="string.jpg" alt="string.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 16:19:43 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9619#M3919</guid>
      <dc:creator>gary1</dc:creator>
      <dc:date>2025-04-11T16:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Transform query result to nested list / nested json with multiple levels</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9623#M3922</link>
      <description>&lt;P&gt;Yep - thanks that was the simple catch.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 18:10:05 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/transform-query-result-to-nested-list-nested-json-with-multiple/m-p/9623#M3922</guid>
      <dc:creator>andreasFe</dc:creator>
      <dc:date>2025-04-11T18:10:05Z</dc:date>
    </item>
  </channel>
</rss>

