<?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: how to replace first element of an array using jolt in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/how-to-replace-first-element-of-an-array-using-jolt/m-p/384969#M245580</link>
    <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp;, After i added escaping to $ with double slash it got worked in shift too.&lt;/P&gt;&lt;P&gt;"#\\${netval}": "&amp;amp;3[&amp;amp;2].&amp;amp;1"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks a lot again&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Mar 2024 18:54:43 GMT</pubDate>
    <dc:creator>PradNiFi1236</dc:creator>
    <dc:date>2024-03-13T18:54:43Z</dc:date>
    <item>
      <title>how to replace first element of an array using jolt</title>
      <link>https://community.cloudera.com/t5/Support-Questions/how-to-replace-first-element-of-an-array-using-jolt/m-p/384857#M245521</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to replace first element of an array value&amp;nbsp; i.e would like to replace with first net val with nifi attribute&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;input&lt;/P&gt;&lt;P&gt;{&lt;BR /&gt;"iH": [&lt;BR /&gt;{&lt;BR /&gt;"DN": "711449",&lt;BR /&gt;"iLineList": [&lt;BR /&gt;{&lt;BR /&gt;"DNnumber": "711449",&lt;BR /&gt;"DNLineNumber": 2&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"DNNumber": "711449",&lt;BR /&gt;"DNLineNumber": 3&lt;BR /&gt;}&lt;BR /&gt;],&lt;BR /&gt;"netval": "22.09"&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"DN": "711450",&lt;BR /&gt;"iLineList": [&lt;BR /&gt;{&lt;BR /&gt;"DNnumber": "711450",&lt;BR /&gt;"DNLineNumber": 2&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"DNNumber": "711450",&lt;BR /&gt;"DNLineNumber": 3&lt;BR /&gt;}&lt;BR /&gt;],&lt;BR /&gt;"netval": "11.09"&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;defined SPEC like :&lt;/P&gt;&lt;P&gt;[&lt;BR /&gt;{&lt;BR /&gt;"operation": "shift",&lt;BR /&gt;"spec": {&lt;BR /&gt;"*": {&lt;BR /&gt;"0": {&lt;BR /&gt;"netVal": "iH[&amp;amp;1].netVal[0]",&lt;BR /&gt;"*": "iH[&amp;amp;1].&amp;amp;"&lt;BR /&gt;},&lt;BR /&gt;"*": "&amp;amp;1"&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;},&lt;BR /&gt;{&lt;BR /&gt;"operation": "modify-overwrite-beta",&lt;BR /&gt;"spec": {&lt;BR /&gt;"*": {&lt;BR /&gt;// "invoiceHeader": {&lt;BR /&gt;"0": {&lt;BR /&gt;&lt;BR /&gt;"netVal": "${netVal}"&lt;BR /&gt;}&lt;BR /&gt;// }&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;]&lt;/P&gt;&lt;P&gt;Expected output:&lt;BR /&gt;{&lt;BR /&gt;"iH" : [ {&lt;BR /&gt;"DN" : "711449",&lt;BR /&gt;"iLineList" : [ {&lt;BR /&gt;"DNnumber" : "711449",&lt;BR /&gt;"DNLineNumber" : 2&lt;BR /&gt;}, {&lt;BR /&gt;"DNNumber" : "711449",&lt;BR /&gt;"DNLineNumber" : 3&lt;BR /&gt;} ],&lt;BR /&gt;"netval" : "${netval}"&lt;BR /&gt;}, {&lt;BR /&gt;"DN" : "711450",&lt;BR /&gt;"iLineList" : [ {&lt;BR /&gt;"DNnumber" : "711450",&lt;BR /&gt;"DNLineNumber" : 2&lt;BR /&gt;}, {&lt;BR /&gt;"DNNumber" : "711450",&lt;BR /&gt;"DNLineNumber" : 3&lt;BR /&gt;} ],&lt;BR /&gt;"netval" : "11.09"&lt;BR /&gt;} ]&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 19:57:33 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/how-to-replace-first-element-of-an-array-using-jolt/m-p/384857#M245521</guid>
      <dc:creator>PradNiFi1236</dc:creator>
      <dc:date>2024-03-11T19:57:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace first element of an array using jolt</title>
      <link>https://community.cloudera.com/t5/Support-Questions/how-to-replace-first-element-of-an-array-using-jolt/m-p/384863#M245526</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This is interesting . It looks trivial initially but its not that simple &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; It took me trial and error to get it to work using modify-overwrite-beta because the syntax is different from the shift spec where you reference array element at n index as "n" while in modify-overwrite-beta its "[0]" ! not sure why the difference.&amp;nbsp; So this should work:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "iH": {
        "[0]": {
          "netval": "${netval}"
        }
      }
    }
}
]&lt;/LI-CODE&gt;&lt;P&gt;You can also do it using shift as follows:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "0": {
          "netval": {
            "#${netval}": "&amp;amp;3[&amp;amp;2].&amp;amp;1"
          },
          "*": "&amp;amp;2[&amp;amp;1].&amp;amp;"
        },
        "*": "&amp;amp;1[&amp;amp;]"
      }
    }
}
]&lt;/LI-CODE&gt;&lt;P&gt;If that helps please accept solution.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 02:33:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/how-to-replace-first-element-of-an-array-using-jolt/m-p/384863#M245526</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2024-03-12T02:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace first element of an array using jolt</title>
      <link>https://community.cloudera.com/t5/Support-Questions/how-to-replace-first-element-of-an-array-using-jolt/m-p/384907#M245558</link>
      <description>&lt;P&gt;Thanks a Lot the JOLT Master&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp;, Modify-overwrite beta -logic worked perfectly.&lt;/P&gt;&lt;P&gt;but for Shift logic jolt demo throwing an execption&amp;nbsp;Invalid reference key=#${netval} either blank or doesn't start with correct character=$&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2024 17:32:43 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/how-to-replace-first-element-of-an-array-using-jolt/m-p/384907#M245558</guid>
      <dc:creator>PradNiFi1236</dc:creator>
      <dc:date>2024-03-12T17:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to replace first element of an array using jolt</title>
      <link>https://community.cloudera.com/t5/Support-Questions/how-to-replace-first-element-of-an-array-using-jolt/m-p/384969#M245580</link>
      <description>&lt;P&gt;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/80381"&gt;@SAMSAL&lt;/a&gt;&amp;nbsp;, After i added escaping to $ with double slash it got worked in shift too.&lt;/P&gt;&lt;P&gt;"#\\${netval}": "&amp;amp;3[&amp;amp;2].&amp;amp;1"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks a lot again&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 18:54:43 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/how-to-replace-first-element-of-an-array-using-jolt/m-p/384969#M245580</guid>
      <dc:creator>PradNiFi1236</dc:creator>
      <dc:date>2024-03-13T18:54:43Z</dc:date>
    </item>
  </channel>
</rss>

