Hi Helena and All, I have a below example JSON file format. My use case is to read "NAME" variable.
When I execute I got next exception *"Exception in thread "main" org.apache.spark.sql.catalyst.errors.package$TreeNodeException: Unresolved attributes: 'NAME, tree:Project ['NAME] Subquery device"* *Please let me know how to read values from JSON using Spark SQL* *CODE BLOCK :* * val device = sqlContext.jsonFile("hdfs://localhost:9000/user/rajesh/json/test.json") device.registerAsTable("device") device.printSchema val results = sqlContext.sql("SELECT NAME FROM device").collect.foreach(println)* *JSON format :* { "Device 1" : { "NAME" : "Device 1", "GROUP" : "1", "SITE" : "qqq", "DIRECTION" : "East", } "Device 2" : { "NAME" : "Device 2", "GROUP" : "2", "SITE" : "sss", "DIRECTION" : "North", } } On Sat, Dec 13, 2014 at 10:13 PM, Helena Edelson < helena.edel...@datastax.com> wrote: > > One solution can be found here: > https://spark.apache.org/docs/1.1.0/sql-programming-guide.html#json-datasets > > - Helena > @helenaedelson > > On Dec 13, 2014, at 11:18 AM, Madabhattula Rajesh Kumar < > mrajaf...@gmail.com> wrote: > > Hi Team, > > I have a large JSON file in Hadoop. Could you please let me know > > 1. How to read the JSON file > 2. How to parse the JSON file > > Please share any example program based on Scala > > Regards, > Rajesh > > >