Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

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

Solved Go to solution
Highlighted

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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

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

Super 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
Highlighted

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

Super 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

Don't have an account?
Coming from Hortonworks? Activate your account here