Support Questions

Find answers, ask questions, and share your expertise

How to store JSON as TXT file? Please refer screenshot!

avatar

jsonissue.png Getting exception that u have multiple columns and text format can accept 1 column only.

1 ACCEPTED SOLUTION

avatar
Master Guru
@sudhir reddy

Try with csv writer as text expects only one column.

 df.write.mode("overwrite").csv("/user/root/JOUT")

(or)

Convert the df to rdd then use saveAsTextFile to write the json to hdfs

df.rdd.saveAsTextFile("/user/root/JOUT") 

(or)

using .format("json") and save the file to hdfs

df.write.format("json").mode("append").save("/user/root/JOUT")

Some useful links regarding similar errors link1,link2,link3

View solution in original post

1 REPLY 1

avatar
Master Guru
@sudhir reddy

Try with csv writer as text expects only one column.

 df.write.mode("overwrite").csv("/user/root/JOUT")

(or)

Convert the df to rdd then use saveAsTextFile to write the json to hdfs

df.rdd.saveAsTextFile("/user/root/JOUT") 

(or)

using .format("json") and save the file to hdfs

df.write.format("json").mode("append").save("/user/root/JOUT")

Some useful links regarding similar errors link1,link2,link3