Create a JSON file in the Google Drive at a location inside "My Drive".
We will call it 'properties.json'. It has the following contents:
{
"firstname": "Ashish",
"lastname": "Jain",
"country": "India"
}
Next, create "Google Colaboratory" (it will be an .ipynb file) in the Drive.
Follow this sequence: New -> More -> Google Colaboratory
Write this code in the first cell: CELL 1#
from google.colab import drive
drive.mount('/content/drive')
In the output, you get an instruction to follow and authenticate the access to a Drive using an access code.
OUTPUT:
Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=9...
Enter your authorization code:
··········
Mounted at /content/drive
CELL 2#
# load json
path_to_json_file = "/content/drive/My Drive/Colab Notebooks/files_1_1/properties.json"
json_file = open(path_to_json_file, 'r')
loaded_json = json_file.read()
json_file.close()
print(loaded_json)
OUTPUT:
{
"firstname": "Ashish",
"lastname": "Jain",
"country": "India"
}
CELL 3#
import json
with open(path_to_json_file, "r") as content:
print(json.load(content))
OUTPUT:
{ 'firstname': 'Ashish', 'lastname': 'Jain', 'country': 'India' }
Pages
- Index of Lessons in Technology
- Index of Book Summaries
- Index of Book Lists And Downloads
- Index For Job Interviews Preparation
- Index of "Algorithms: Design and Analysis"
- Python Course (Index)
- Data Analytics Course (Index)
- Index of Machine Learning
- Postings Index
- Index of BITS WILP Exam Papers and Content
- Lessons in Investing
- Index of Math Lessons
- Downloads
- Index of Management Lessons
- Book Requests
- Index of English Lessons
- Index of Medicines
- Index of Quizzes (Educational)
Reading a JSON file from the Google Drive in the Google Colab
Subscribe to:
Comments (Atom)

No comments:
Post a Comment