title: Get value from an array in a map based on a key in Scala
body: <p>I have a dataframe with the following schema:</p>
  
  <pre><code> |-- A: map (nullable = true)
   |    |-- key: string
   |    |-- value: array (valueContainsNull = true)
   |    |    |-- element: struct (containsNull = true)
   |    |    |    |-- id: string (nullable = true)
   |    |    |    |-- type: string (nullable = true)
   |    |    |    |-- index: boolean (nullable = false)
   |-- idkey: string (nullable = true)
  </code></pre>
  
  <p>Since the value in the map is of type array, I need to extract the field index corresponding to the id in the "foreign" key field idkey. </p>
  
  <p>For example, I have the following data:</p>
  
  <pre><code> {"A":{
   "innerkey_1":[{"id":"1","type":"0.01","index":true},
                 {"id":"6","type":"4.3","index":false}]},
   "1"}
  </code></pre>
  
  <p>Since the idkey is 1, we need to to output the value of index corresponding to the element where <code>"id":1</code>, i.e. the index should be equal to true. I am really not sure how I can accomplish this, with UDFs or otherwise.</p>
  
  <p>Expected output is: </p>
  
  <pre class="lang-none prettyprint-override"><code>+---------+
  | indexout|
  +---------+
  |   true  |
  +---------+
  </code></pre>