Created 06-23-2016 10:17 PM
I am getting a json response, and in my sparkSQL data source, i need to read the data and infer schema for the json and convert in to rdd<ROW>. Is there any class to do that in spark?
Thanks
Created 06-23-2016 11:32 PM
val dataframe = sqlContext.read.json(<a RDD[String] where each line is JSON object>)
Created 06-23-2016 10:38 PM
Created 06-23-2016 10:47 PM
I dont want to read from files. I have json data in a variable coming from http response in my code.
Created 06-26-2016 01:54 AM
So, even following wont work for you? If not, I think currently there is no other way given we have looked at all other possible options.
//a DataFrame can be created for a JSON dataset represented by
// an RDD[String] storing one JSON object per string.
val anotherPeopleRDD = sc.parallelize(
"""{"name":"Yin","address":{"city":"Columbus","state":"Ohio"}}""" :: Nil)
val anotherPeople = sqlContext.read.json(anotherPeopleRDD)
Created 06-23-2016 10:58 PM
@Akash Mehta Can you do something like this?
dataframe = sqlContext.read.format(“json”).load(your json here)
Created 06-23-2016 11:04 PM
But "your json here" takes a path and i am having the json from an httpresponse (converted to string).
I need to read from that and infer the schema and convert to rdd<ROW>
Created 06-23-2016 11:51 PM
load will infer schema and convert to a row. Question is whether it will take an http url. Can you try?
Created 06-24-2016 07:00 PM
Yes yes load will do that but load requires an input path and i have my json stored in a string variable.
Created 06-23-2016 11:32 PM
val dataframe = sqlContext.read.json(<a RDD[String] where each line is JSON object>)
Created 06-24-2016 01:14 AM
This will output a dataframe and i need RDD[Row]