<?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 JSON - Select Parent Field in Workato Pros Discussion Board</title>
    <link>https://systematic.workato.com/t5/workato-pros-discussion-board/json-select-parent-field/m-p/6788#M2929</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; I've tried to find an answer to this one but haven't had success.&amp;nbsp; I have the below JSON structure (with roughly 5,000 records) returned from an API.&lt;/P&gt;&lt;PRE&gt;{&lt;BR /&gt;  "employees": [&lt;BR /&gt;    {&lt;BR /&gt;      "/work/employeeIdInCompany": {&lt;BR /&gt;        "value": 654321&lt;BR /&gt;      },&lt;BR /&gt;      "work": {&lt;BR /&gt;        "employeeIdInCompany": 654321&lt;BR /&gt;      },&lt;BR /&gt;      "id": "32184129999999999999"&lt;BR /&gt;    },&lt;BR /&gt;    {&lt;BR /&gt;      "/work/employeeIdInCompany": {&lt;BR /&gt;        "value": 123456&lt;BR /&gt;      },&lt;BR /&gt;      "work": {&lt;BR /&gt;        "employeeIdInCompany": 123456&lt;BR /&gt;      },&lt;BR /&gt;      "id": "3218412688888888888"&lt;BR /&gt;    },&lt;BR /&gt;    ...&lt;BR /&gt;  ]&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;What I need to do is pull the longer ID field where the &lt;EM&gt;employeeIdInCompany&lt;/EM&gt; value matches the current search criteria.&amp;nbsp; For example, where the &lt;EM&gt;employeeIdInCompany&lt;/EM&gt; is &lt;STRONG&gt;123456&lt;/STRONG&gt;, I need to pull&amp;nbsp;&lt;STRONG&gt;3218412688888888888&lt;/STRONG&gt; from the above JSON.&lt;/P&gt;&lt;P&gt;I know how to use where and pluck where the search item is at or above the level of the field to be pulled, but at a bit of a loss where the search item is nested like this.&lt;/P&gt;&lt;P&gt;Thank You&lt;/P&gt;&lt;P&gt;Gareth&lt;/P&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>Thu, 30 May 2024 04:57:06 GMT</pubDate>
    <dc:creator>GarethMHC</dc:creator>
    <dc:date>2024-05-30T04:57:06Z</dc:date>
    <item>
      <title>JSON - Select Parent Field</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/json-select-parent-field/m-p/6788#M2929</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; I've tried to find an answer to this one but haven't had success.&amp;nbsp; I have the below JSON structure (with roughly 5,000 records) returned from an API.&lt;/P&gt;&lt;PRE&gt;{&lt;BR /&gt;  "employees": [&lt;BR /&gt;    {&lt;BR /&gt;      "/work/employeeIdInCompany": {&lt;BR /&gt;        "value": 654321&lt;BR /&gt;      },&lt;BR /&gt;      "work": {&lt;BR /&gt;        "employeeIdInCompany": 654321&lt;BR /&gt;      },&lt;BR /&gt;      "id": "32184129999999999999"&lt;BR /&gt;    },&lt;BR /&gt;    {&lt;BR /&gt;      "/work/employeeIdInCompany": {&lt;BR /&gt;        "value": 123456&lt;BR /&gt;      },&lt;BR /&gt;      "work": {&lt;BR /&gt;        "employeeIdInCompany": 123456&lt;BR /&gt;      },&lt;BR /&gt;      "id": "3218412688888888888"&lt;BR /&gt;    },&lt;BR /&gt;    ...&lt;BR /&gt;  ]&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;What I need to do is pull the longer ID field where the &lt;EM&gt;employeeIdInCompany&lt;/EM&gt; value matches the current search criteria.&amp;nbsp; For example, where the &lt;EM&gt;employeeIdInCompany&lt;/EM&gt; is &lt;STRONG&gt;123456&lt;/STRONG&gt;, I need to pull&amp;nbsp;&lt;STRONG&gt;3218412688888888888&lt;/STRONG&gt; from the above JSON.&lt;/P&gt;&lt;P&gt;I know how to use where and pluck where the search item is at or above the level of the field to be pulled, but at a bit of a loss where the search item is nested like this.&lt;/P&gt;&lt;P&gt;Thank You&lt;/P&gt;&lt;P&gt;Gareth&lt;/P&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>Thu, 30 May 2024 04:57:06 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/json-select-parent-field/m-p/6788#M2929</guid>
      <dc:creator>GarethMHC</dc:creator>
      <dc:date>2024-05-30T04:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: JSON - Select Parent Field</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/json-select-parent-field/m-p/6790#M2930</link>
      <description>&lt;P&gt;It's a bit of an eyesore, but this is about as elegant as Ruby can do it. Ugly or not, it works and it's a single action.&lt;/P&gt;&lt;P&gt;It assumes a few things:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Each object in your "employees" array will always have a "work" object with an "employeeIdInCompany" value.&lt;/LI&gt;&lt;LI&gt;Each object will always have an "id" value.&lt;/LI&gt;&lt;LI&gt;Each "employeeIdInCompany" value is unique and will not repeat in the array.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;If those three assumptions are okay, then this will probably work for you.&lt;/P&gt;&lt;P&gt;I put your sample payload in a logger message and accessed it from there. Assume "message" in the below is a data pill containing your sample data. If you already have a data pill for "employees", you can just use that instead of "message["employees"]"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="ruby"&gt;message["employees"][message["employees"].pluck("work").pluck("employeeIdInCompany").find_index(123456)]["id"]&lt;/LI-CODE&gt;&lt;P&gt;It should look like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="where.png" style="width: 999px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/1311iDD1DD3E25F4128BE/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="where.png" alt="where.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2024 06:20:10 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/json-select-parent-field/m-p/6790#M2930</guid>
      <dc:creator>gary1</dc:creator>
      <dc:date>2024-05-30T06:20:10Z</dc:date>
    </item>
    <item>
      <title>Re: JSON - Select Parent Field</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/json-select-parent-field/m-p/6795#M2934</link>
      <description>&lt;P&gt;Awesome, that worked a treat, thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 04:52:19 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/json-select-parent-field/m-p/6795#M2934</guid>
      <dc:creator>GarethMHC</dc:creator>
      <dc:date>2024-05-31T04:52:19Z</dc:date>
    </item>
  </channel>
</rss>

