title: Spark Dataframe - how to access json structure
body: <p>I have a json file look like this:</p>
  
  <pre><code>{
    "employeeDetails":{
      "name": "xxxx",
      "num":"415"
    },
    "work":[
      {
        "monthYear":"01/2007",
        "workdate":"1|2|3|....|31",
        "workhours":"8|8|8....|8"
      },
      {
        "monthYear":"02/2007",
        "workdate":"1|2|3|....|31",
        "workhours":"8|8|8....|8"
      }
    ]
  }
  </code></pre>
  
  <p><em>I have to get the workdate, workhours from this json data.</em></p>
  
  <p>I am using Spark 2.1.1</p>
  
  <p>I tried like this:</p>
  
  <pre><code>     val spark = SparkSession.builder().appName("SQL-JSON").master("local[4]").getOrCreate()
  
       val df = spark.read.json(spark.sparkContext.wholeTextFiles("sample22.json").values)
       // df.show()
       // df.printSchema()
  
      //val gatewayMessageContent = df.select("employeeDetails")
      //gatewayMessageContent.printSchema()
      val sensorMessagesContent = df.select("work")
      sensorMessagesContent.printSchema()
  
      // I am fallowing one article online, it showing like this, but it not working for me.
      val flattened = df.select(  $"root", explode($"work").as("work_flat"))
  </code></pre>
  
  <p>I am geting exception like this:</p>
  
  <pre><code>Error:(22, 31) value $ is not a member of StringContext
  val flattened = df.select($"root", explode($"work").as("work_flat"))
                            ^
  Error:(22, 48) value $ is not a member of StringContext
  val flattened = df.select($"root", explode($"work").as("work_flat"))
                                             ^
  </code></pre>
  
  <p>In that example what he showed there is 'name' in top level. But my case I don't have any top element('work'). Because of that it not working.</p>
  
  <p>I am new to Spark. </p>