<?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>question Re: jolt transform ( add array elements to a different existing object ) in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/jolt-transform-add-array-elements-to-a-different-existing/m-p/397066#M249688</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/119188"&gt;@fisblack&lt;/a&gt;&amp;nbsp;Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future.&amp;nbsp; Thanks.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Nov 2024 15:38:59 GMT</pubDate>
    <dc:creator>DianaTorres</dc:creator>
    <dc:date>2024-11-06T15:38:59Z</dc:date>
    <item>
      <title>jolt transform ( add array elements to a different existing object )</title>
      <link>https://community.cloudera.com/t5/Support-Questions/jolt-transform-add-array-elements-to-a-different-existing/m-p/396577#M249469</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello , can anyone help with a spec to transform this JSON input to the desired output .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;JSON INPUT&lt;/P&gt;&lt;P&gt;==========&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;"courseId": "xxx"&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;== desired output json ==&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"courseId": "xxx",&lt;BR /&gt;"courseSubCategory": 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;},&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"courseId": "xxx",&lt;BR /&gt;"courseSubCategory": 2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;},&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;"courseId": "xxx",&lt;BR /&gt;"courseSubCategory": 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 10:20:24 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/jolt-transform-add-array-elements-to-a-different-existing/m-p/396577#M249469</guid>
      <dc:creator>fisblack</dc:creator>
      <dc:date>2024-10-30T10:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: jolt transform ( add array elements to a different existing object )</title>
      <link>https://community.cloudera.com/t5/Support-Questions/jolt-transform-add-array-elements-to-a-different-existing/m-p/396581#M249470</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/119188"&gt;@fisblack&lt;/a&gt; ,&lt;/P&gt;&lt;P&gt;Welcome to the community.&lt;/P&gt;&lt;P&gt;Your transformation is kind of odd. Usually transformation is driven by existing values or structure&amp;nbsp; even when generating new fields with defaults. I have never seen a case where newly generated values drive transformation of existing ones. I assume you are getting the list of courseSubCategory from somewhere and the&amp;nbsp; script is rather dynamic utilizing some expression language &amp;amp; attributes. if you provide some context to how the list is coming about and what are you trying to achieve , maybe we can provide you with more accurate solution.&lt;/P&gt;&lt;P&gt;There are multiple ways of solving your problem as is - assuming you always want to replicate an existing field(s) against&amp;nbsp; newly generated 3 elements array with default&amp;nbsp; values of 1,2&amp;amp;3- , here is one of them:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "*": "existing.&amp;amp;",
      "#1|#2|#3": "courseSubCategory"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "courseSubCategory": {
        "*": {
          "@(2,existing)": "[&amp;amp;1]",
          "@": "[&amp;amp;1].courseSubCategory"
        }
      }
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;If you want to make this more dynamic in terms of number of "courseSubCatgory", you can construct the array assignment string "#1|#2|#3" in some upstream processors and store the value as flow attribute (let says its called the same) , then you can make it more dynamic by using the flowfile attribute where the assignment of the courseSubCategory in the first shift will look like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;"${courseSubCategory}": "courseSubCategory"&lt;/LI-CODE&gt;&lt;P&gt;Hope that helps. If it does help, please accept the solution.&lt;/P&gt;&lt;P&gt;Thanks&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>Wed, 30 Oct 2024 11:41:26 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/jolt-transform-add-array-elements-to-a-different-existing/m-p/396581#M249470</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2024-10-30T11:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: jolt transform ( add array elements to a different existing object )</title>
      <link>https://community.cloudera.com/t5/Support-Questions/jolt-transform-add-array-elements-to-a-different-existing/m-p/397066#M249688</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/119188"&gt;@fisblack&lt;/a&gt;&amp;nbsp;Has the reply helped resolve your issue? If so, please mark the appropriate reply as the solution, as it will make it easier for others to find the answer in the future.&amp;nbsp; Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2024 15:38:59 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/jolt-transform-add-array-elements-to-a-different-existing/m-p/397066#M249688</guid>
      <dc:creator>DianaTorres</dc:creator>
      <dc:date>2024-11-06T15:38:59Z</dc:date>
    </item>
  </channel>
</rss>

