How to import json file to mongodb using pyspark (or python)?

0 votes

I'm try to import json in the file to mongodb using pyspark after connection pyspark with mongodb, I'm using Ubuntu, my file in (file:///home/user/Downloads/newdb/hale.json) I write it like this ('home/user/Downloads/newdb/hale.json'),

I want to try using this code but in JSON

df = spark.read.csv(path = '/home/ahmad/Downloads/newdb/hale.csv', header=True, inferSchema=True)

??

Sep 8, 2019 in Python by Ahmed
• 310 points

edited Sep 9, 2019 by Omkar 397 views

1 answer to this question.

0 votes

You can use the same format as in your question but replace csv with json. 

df = spark.read.json(path = '/home/ahmad/Downloads/newdb/hale.json', header=True, inferSchema=True)
answered Sep 9, 2019 by Karan
Thank you, I did this code but doesn't work :(
Hey @Ahmed. Can you share the error that you got?

Related Questions In Python

0 votes
0 answers

How to save the import csv file to mongodb using pyspark (or python)?

I have this code, and I want ...READ MORE

Oct 9, 2019 in Python by Ahmed
• 310 points
642 views
0 votes
1 answer
0 votes
1 answer

How to download a file over HTTP using Python?

In Python 2, use urllib2 which comes ...READ MORE

answered Oct 18, 2018 in Python by SDeb
• 13,250 points
150 views
0 votes
1 answer

How to check latest change time of each file using glob in python?

You can get the changing time from ...READ MORE

answered Jan 2, 2019 in Python by Omkar
• 69,040 points
158 views
+2 votes
1 answer
0 votes
1 answer

How to sort json file ascending in pymongo?

Hey Ahmad, you can get the output ...READ MORE

answered Aug 14, 2019 in Python by Trisha
141 views
+1 vote
1 answer

How to read hdfs file using python?

subprocess.Popen(["hadoop", "fs", "-cat", "/path/to/myfile"], stdou ...READ MORE

answered Dec 6, 2018 in Python by Omkar
• 69,040 points
2,894 views
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,770 points
5,188 views