Question: I want to read json or xml file in pyspark.lf my file is split in multiple line in

```
rdd= sc.textFile(json or xml) 

```

Input

```
{
" employees":
[
 {
 "firstName":"John",
 "lastName":"Doe" 
},
 { 
"firstName":"Anna"
  ]
}

```

Input is spread across multiple lines.

Expected Output `{"employees:[{"firstName:"John",......]}`

How to get the complete file in a single line using pyspark?

Answer: 
If your data is not formed on one line as `textFile` expects, then use `wholeTextFiles`.

This will give you the whole file so that you can parse it down into whatever format you would like.
"How to read whole [HDFS] file in one string [in Spark, to use as sql]":
------------------------------------------------------------------------

e.g.

```
// Put file to hdfs from edge-node's shell...

hdfs dfs -put <filename>

// Within spark-shell...

// 1. Load file as one string
val f = sc.wholeTextFiles("hdfs:///user/<username>/<filename>")
val hql = f.take(1)(0)._2

// 2. Use string as sql/hql
val hiveContext = new org.apache.spark.sql.hive.HiveContext(sc)
val results = hiveContext.sql(hql)

```