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: 
This is how you would do in scala

```
rdd = sc.wholeTextFiles("hdfs://nameservice1/user/me/test.txt")
rdd.collect.foreach(t=>println(t._2))

```
Python way

```
rdd = spark.sparkContext.wholeTextFiles("hdfs://nameservice1/user/me/test.txt")
json = rdd.collect()[0][1]

```