Sadasiba Sahoo
Sadasiba Sahoo

Reputation: 129

How to convert spark response to JSON object

val conf = new SparkConf().setAppName("test").setMaster("local")
val sc = new SparkContext(conf)
val sqlContext = new SQLContext(sc)
val input = sqlContext.read.json("input.json")
input.select("email", "first_name").where("email=='[email protected]'").show()

I am getting following response

enter image description here

How can I get response as a JSON Object?

Upvotes: 0

Views: 688

Answers (1)

Rafaël
Rafaël

Reputation: 1027

You can write it to Json File : https://www.tutorialkart.com/apache-spark/spark-write-dataset-to-json-file-example/

Or if you prefer to show it as a Dataset of Json Strings, use the toJSON function :

input
  .select("email", "first_name")
  .where("email=='[email protected]'")
  .toJSON()
  .show()

Upvotes: 2

Related Questions