<?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 How to convert two arrays to key value with Jolt? in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/How-to-convert-two-arrays-to-key-value-with-Jolt/m-p/283154#M210467</link>
    <description>&lt;P&gt;I have some JSON that contains two arrays that I would like to convert to key/value pairs. I've already create a spec to convert my input data into the format below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input&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;&lt;LI-CODE lang="markup"&gt;{
  "rows" : [ {
    "row" : [ "row1", "row2", "row3" ],
    "header" : [ "header1", "header2", "header3" ]
  }, {
    "row" : [ "row4", "row5", "row6" ],
    "header" : [ "header1", "header2", "header3" ]
  } ]
}&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to convert it again with Jolt to something like:&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
"header1" : "row1",
"header2" : "row2",
"header3" : "row3",
"header1" : "row4",
"header2" : "row5",
"header3" : "row6"
}&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any guidance would be highly appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 16 Nov 2019 16:49:16 GMT</pubDate>
    <dc:creator>DataD</dc:creator>
    <dc:date>2019-11-16T16:49:16Z</dc:date>
    <item>
      <title>How to convert two arrays to key value with Jolt?</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-convert-two-arrays-to-key-value-with-Jolt/m-p/283154#M210467</link>
      <description>&lt;P&gt;I have some JSON that contains two arrays that I would like to convert to key/value pairs. I've already create a spec to convert my input data into the format below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input&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;&lt;LI-CODE lang="markup"&gt;{
  "rows" : [ {
    "row" : [ "row1", "row2", "row3" ],
    "header" : [ "header1", "header2", "header3" ]
  }, {
    "row" : [ "row4", "row5", "row6" ],
    "header" : [ "header1", "header2", "header3" ]
  } ]
}&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to convert it again with Jolt to something like:&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
"header1" : "row1",
"header2" : "row2",
"header3" : "row3",
"header1" : "row4",
"header2" : "row5",
"header3" : "row6"
}&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any guidance would be highly appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2019 16:49:16 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-convert-two-arrays-to-key-value-with-Jolt/m-p/283154#M210467</guid>
      <dc:creator>DataD</dc:creator>
      <dc:date>2019-11-16T16:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert two arrays to key value with Jolt?</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-convert-two-arrays-to-key-value-with-Jolt/m-p/283165#M210473</link>
      <description>&lt;P&gt;If the original input data (before your Jolt transform) looks something like this...&lt;/P&gt;&lt;PRE&gt;{
  "headers": [
    "header1",
    "header2",
    "header3"
  ],
  "rows": [
    [
      "row1",
      "row2",
      "row3"
    ],
    [
      "row4",
      "row5",
      "row6"
    ]
  ]
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;...then it may be easier using SplitJSON and EvaluateJSONPath processors in this scenario.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The GenerateFlowFile processor has some sample data that matches the above format using books as the example. The result will be a separate JSON file for each array within "rows". You can configure the MergeContent to bundle the JSON records as needed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-11-16 at 5.08.14 PM.png" style="width: 999px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/25334iBED36B9463C2BB83/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2019-11-16 at 5.08.14 PM.png" alt="Screen Shot 2019-11-16 at 5.08.14 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;EvaluateJSONPath&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-11-16 at 5.13.45 PM.png" style="width: 791px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/25338iF0FC036E74AEC420/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2019-11-16 at 5.13.45 PM.png" alt="Screen Shot 2019-11-16 at 5.13.45 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;SplitJSON&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-11-16 at 5.14.49 PM.png" style="width: 803px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/25336iBAFFCAD5BC1F2522/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2019-11-16 at 5.14.49 PM.png" alt="Screen Shot 2019-11-16 at 5.14.49 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;EvaluateJSONPath&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-11-16 at 5.14.59 PM.png" style="width: 808px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/25335i602444BF697856A9/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2019-11-16 at 5.14.59 PM.png" alt="Screen Shot 2019-11-16 at 5.14.59 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ReplaceText&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2019-11-16 at 5.15.09 PM.png" style="width: 798px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/25337iF07B4A8DA796967E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2019-11-16 at 5.15.09 PM.png" alt="Screen Shot 2019-11-16 at 5.15.09 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2019 22:19:13 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-convert-two-arrays-to-key-value-with-Jolt/m-p/283165#M210473</guid>
      <dc:creator>marcusmattson</dc:creator>
      <dc:date>2019-11-16T22:19:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert two arrays to key value with Jolt?</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-convert-two-arrays-to-key-value-with-Jolt/m-p/303761#M221698</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.cloudera.com/t5/user/viewprofilepage/user-id/71316"&gt;@DataD&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Please find the below spec:&lt;/P&gt;&lt;PRE&gt;[&lt;BR /&gt; {&lt;BR /&gt;  "operation": "shift",&lt;BR /&gt;  "spec": {&lt;BR /&gt;   "rows": {&lt;BR /&gt;    "*": {&lt;BR /&gt;     "row": {&lt;BR /&gt;      "*": {&lt;BR /&gt;       "@": "[&amp;amp;3].@(3,header[&amp;amp;1])"&lt;BR /&gt;      }&lt;BR /&gt;     }&lt;BR /&gt;    }&lt;BR /&gt;   }&lt;BR /&gt;  }&lt;BR /&gt; }&lt;BR /&gt;]&lt;/PRE&gt;&lt;P&gt;This will give the output as:&lt;/P&gt;&lt;PRE&gt;[ {&lt;BR /&gt;"header1" : "row1",&lt;BR /&gt;"header2" : "row2",&lt;BR /&gt;"header3" : "row3"&lt;BR /&gt;}, {&lt;BR /&gt;"header1" : "row4",&lt;BR /&gt;"header2" : "row5",&lt;BR /&gt;"header3" : "row6"&lt;BR /&gt;} ]&lt;/PRE&gt;&lt;P&gt;I didn't convert it to&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{
"header1" : "row1",
"header2" : "row2",
"header3" : "row3",
"header1" : "row4",
"header2" : "row5",
"header3" : "row6"
}&lt;/PRE&gt;&lt;P&gt;because that is not a valid json as header1,2 and 3 are repeated keys in the same level of the json.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 18:25:54 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-convert-two-arrays-to-key-value-with-Jolt/m-p/303761#M221698</guid>
      <dc:creator>PVVK</dc:creator>
      <dc:date>2020-09-30T18:25:54Z</dc:date>
    </item>
  </channel>
</rss>

