<?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 Looping through parsed JSON to get key and value in Workato Pros Discussion Board</title>
    <link>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/5156#M2277</link>
    <description>&lt;P&gt;I&amp;nbsp; have a GET command that returns a JSON response.The next step is Parse JSON. From there, I want to loop through the "key" and "value". &lt;SPAN&gt;The Parsed JSON turns the fields into datapills, which I can pull the value, but I can't get the "key" (label). Is this possible?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Sep 2023 13:30:41 GMT</pubDate>
    <dc:creator>moxiego</dc:creator>
    <dc:date>2023-09-20T13:30:41Z</dc:date>
    <item>
      <title>Looping through parsed JSON to get key and value</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/5156#M2277</link>
      <description>&lt;P&gt;I&amp;nbsp; have a GET command that returns a JSON response.The next step is Parse JSON. From there, I want to loop through the "key" and "value". &lt;SPAN&gt;The Parsed JSON turns the fields into datapills, which I can pull the value, but I can't get the "key" (label). Is this possible?&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 13:30:41 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/5156#M2277</guid>
      <dc:creator>moxiego</dc:creator>
      <dc:date>2023-09-20T13:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through parsed JSON to get key and value</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/5159#M2280</link>
      <description>&lt;P&gt;Create a Ruby action and use the following code. Create an input called "obj" and use the object data pill. It will output an array of objects with key/value keys that are easier to loop through in a traditional Workato loop.&lt;/P&gt;&lt;P&gt;Ruby code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;obj = input["obj"]
array = [] 

input["obj"].keys.each { | k | 
  array.push({"key": k, "value": obj[k]})
}
  
{output: array}
  &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example input object:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;{"one": 1, "two": 2, "three": 3}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;{
	"output": {
		"output": [
			{
				"key": "one",
				"value": 1
			},
			{
				"key": "two",
				"value": 2
			},
			{
				"key": "three",
				"value": 3
			}
		]
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 16:22:27 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/5159#M2280</guid>
      <dc:creator>gary1</dc:creator>
      <dc:date>2023-09-20T16:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through parsed JSON to get key and value</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/5169#M2285</link>
      <description>&lt;P&gt;Thank you! I was able to turn it into python code that worked for me.&lt;/P&gt;&lt;P&gt;def main(input):&lt;BR /&gt;data = input.get("jsondata", [])&lt;BR /&gt;output_list = []&lt;/P&gt;&lt;P&gt;for item in data:&lt;BR /&gt;custom_fields = item.get("custom_fields", {})&lt;BR /&gt;for key, value in custom_fields.items():&lt;BR /&gt;output_list.append({"key": key, "value": value})&lt;/P&gt;&lt;P&gt;return {'output_q' : output_list}&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 13:53:37 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/5169#M2285</guid>
      <dc:creator>moxiego</dc:creator>
      <dc:date>2023-09-21T13:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through parsed JSON to get key and value</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/5170#M2286</link>
      <description>&lt;P&gt;This is such a useful and common requirement that I really hope Workato can build it into a standard function.&amp;nbsp; I had to ask for help to do this with Ruby years ago. Surely many customers come across this requirement/shortfall in functionality all the time.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 14:04:06 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/5170#M2286</guid>
      <dc:creator>dcornwell</dc:creator>
      <dc:date>2023-09-21T14:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through parsed JSON to get key and value</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/5171#M2287</link>
      <description>&lt;P&gt;It's a tough choice between this or fixing the "triple click list" bug!&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 15:00:31 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/5171#M2287</guid>
      <dc:creator>gary1</dc:creator>
      <dc:date>2023-09-21T15:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through parsed JSON to get key and value</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/6172#M2721</link>
      <description>&lt;P&gt;would mind to answer how can I map these key value to data model?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Feb 2024 03:45:24 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/6172#M2721</guid>
      <dc:creator>Prachi_chakke</dc:creator>
      <dc:date>2024-02-29T03:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: Looping through parsed JSON to get key and value</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/6191#M2728</link>
      <description>&lt;P&gt;Step 10: In the above code, we get the output_q as the key/value list.&lt;/P&gt;&lt;P&gt;Step 11: "for each item in output_q (prev step) repeat the following steps"&lt;/P&gt;&lt;P&gt;Then I update previously declared variables&lt;/P&gt;&lt;P&gt;Primary Supervisor: KeyStep11.match?(/primary_supervisor/).present?? ValueStep11 : skip&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 15:46:19 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/looping-through-parsed-json-to-get-key-and-value/m-p/6191#M2728</guid>
      <dc:creator>moxiego</dc:creator>
      <dc:date>2024-03-01T15:46:19Z</dc:date>
    </item>
  </channel>
</rss>

