title: Filter array of struct in spark dataframe
body: <p>I have a JSON file that I am reading into <strong>Spark dataframe using Scala 2.10</strong> with</p>
  
  <pre><code>val df = sqlContext.read.json("file_path")
  </code></pre>
  
  <p>JSON looks like below:</p>
  
  <pre><code>{ "data": [{ "id":"20180218","parent": [{"name": "Market"}]}, { "id":"20180219","parent": [{"name": "Client"},{"name": "Market" }]}, { "id":"20180220","parent": [{"name": "Client"}]},{ "id":"20180221","parent": []}]}
  </code></pre>
  
  <p>data is an array of struct. Each struct again has parent key. Parent is again an array of struct which can hold 0 or more values. </p>
  
  <p>I need to filter the parent array such that it holds only the structs that have name either "Market" or nothing. My output should look like:</p>
  
  <pre><code>{ "data": [{ "id":"20180218","parent": [{"name": "Market"}]}, { "id":"20180219","parent": [{"name": "Market" }]}, { "id":"20180220","parent": []},{ "id":"20180221","parent": []}]}
  </code></pre>
  
  <p>So, basically filter out every struct that has name anything other than "Market" and keep the empty parent array (as a result of the operation, or if it was already empty).</p>
  
  <p>Can somebody help out here?</p>
  
  <p>Thanks</p>