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 in Python by Ahmed
• 310 points

edited Sep 9 by Omkar 117 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 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 in Python by Ahmed
• 310 points
171 views
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,190 points
61 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 in Python by Omkar
• 67,660 points
74 views
0 votes
1 answer

How to use read a WSDL file from the file system using Python suds?

Hi, good question. It is a very simple ...READ MORE

answered Jan 21 in Python by Nymeria
• 3,520 points
686 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 348 views
+1 vote
1 answer

How to read hdfs file using python?

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

answered Dec 6, 2018 in Python by Omkar
• 67,660 points
1,261 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,720 points
2,254 views