<?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: Convert a Map Field into an Array in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/Convert-a-Map-Field-into-an-Array/m-p/353469#M236715</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it always the case that when you have one address you will have a map and if its multiple addresses then its an array? If that is true, then can use the EvaluateJsonPath processor to get the size of child elements of the "addresses" key with the following json path expression:&lt;/P&gt;&lt;P&gt;$.addresses.length()&lt;/P&gt;&lt;P&gt;If you have one address then the result is 1 otherwise &amp;gt;1. Then you can use RouteOnAttribute when the length is 1 to Jolt Transformation processor with the following spec to convert to Array:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "addresses": {
        "*": "addresses.[].&amp;amp;"
      },
      "*": "&amp;amp;"
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Sep 2022 16:16:47 GMT</pubDate>
    <dc:creator>SAMSAL</dc:creator>
    <dc:date>2022-09-27T16:16:47Z</dc:date>
    <item>
      <title>Convert a Map Field into an Array</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-a-Map-Field-into-an-Array/m-p/353363#M236698</link>
      <description>&lt;P&gt;If I have a flow file with the following JSON how can I&lt;/P&gt;&lt;P&gt;1) Evaluate "addresses" to determine if it is of type Array or type Map&lt;/P&gt;&lt;P&gt;2) If type Map then&amp;nbsp;convert "addresses" into an array using native NiFi capabilities (i.e. no string parsing)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
    "name": "John Doe",
    "addresses": {
        "work": {
            "number": "123",
            "street": "5th Avenue",
            "city": "New York",
            "state": "NY",
            "zip": "10020"
        }
    }
}&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;This is what I need it to look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
    "name": "John Doe",
    "addresses": [{
        "work": {
            "number": "123",
            "street": "5th Avenue",
            "city": "New York",
            "state": "NY",
            "zip": "10020"
        }
    }]
}&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;I appreciate the input and support!&amp;nbsp; Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 05:41:53 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-a-Map-Field-into-an-Array/m-p/353363#M236698</guid>
      <dc:creator>ChuckE</dc:creator>
      <dc:date>2022-09-27T05:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a Map Field into an Array</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-a-Map-Field-into-an-Array/m-p/353469#M236715</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it always the case that when you have one address you will have a map and if its multiple addresses then its an array? If that is true, then can use the EvaluateJsonPath processor to get the size of child elements of the "addresses" key with the following json path expression:&lt;/P&gt;&lt;P&gt;$.addresses.length()&lt;/P&gt;&lt;P&gt;If you have one address then the result is 1 otherwise &amp;gt;1. Then you can use RouteOnAttribute when the length is 1 to Jolt Transformation processor with the following spec to convert to Array:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[
  {
    "operation": "shift",
    "spec": {
      "addresses": {
        "*": "addresses.[].&amp;amp;"
      },
      "*": "&amp;amp;"
    }
  }
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 16:16:47 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-a-Map-Field-into-an-Array/m-p/353469#M236715</guid>
      <dc:creator>SAMSAL</dc:creator>
      <dc:date>2022-09-27T16:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a Map Field into an Array</title>
      <link>https://community.cloudera.com/t5/Support-Questions/Convert-a-Map-Field-into-an-Array/m-p/353473#M236719</link>
      <description>&lt;P&gt;Brilliant!&amp;nbsp; Exactly what I was looking for.&amp;nbsp; Although it seems a little peculiar to me that we need to rely on a Jolt transform for this operation and not the UpdateRecord processor. Particularly since NiFi makes it a point to discuss Arrays and Maps in the documentation.&lt;/P&gt;&lt;P&gt;Thanks for the Jolt transform because I spent a lot of time trying to get the Jolt transform to work and couldn't quite figure it out.&amp;nbsp; Now I see what I was doing wrong.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 18:26:10 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/Convert-a-Map-Field-into-an-Array/m-p/353473#M236719</guid>
      <dc:creator>ChuckE</dc:creator>
      <dc:date>2022-09-27T18:26:10Z</dc:date>
    </item>
  </channel>
</rss>

