Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to read json file
#21
A part of problem is that you struggle with basic understating of this Undecided
I gone explain in detail under here,if this don't work ask someone to help you local.
jk91 Wrote:i tried to download from your link but after downloading it,i can not open it and my computer
There is no need to open data.json(then you can mess it up if save it),you shall just open colab then File --> New Notebook .
You copy is this code:
# test_read.py
import json
from pprint import pprint
 
with open("data.json", "r") as read_file:
    data = json.load(read_file)
 
pprint(data)
Then on Files left side menu,here you choice upload as in image.
Now find data.json on your hard-drive and upload.
Now push Run Cell button and it should work.
jk91 Wrote:my computer say's look for appropriate program from internet to open such files also i tried to save my data.json
That because you have not JSON set to open in a program file associations.
This is is how it should be you can choice what you want eg basic notepad or better a basic editor like Notepad ++.

jk91 Wrote:last post as .ipynd in file extension but some how that notepad file gets saved in .txt format only not sure what is wrong here.
You most be careful to save in notepad all will be .txt default,have to choice all files the type file name wanted and save.
Why to do talk about .ipynd,do as posted here,
after you get all to work you can download the Notebook the it will in .ipynd format.
Here have i downloaded it and share it with nbviewer My Notebook.
Reply
#22
any updates please?

(Feb-23-2020, 04:26 PM)jk91 Wrote: any updates please?

please ignore my last follow up post asking for update as i did not see recent reply sorry for that.

but as suggested i again tried to upload data.json text file as a notepad form to colab file-upload new file but again and again receiving same error as attached here.

Attached Files

Thumbnail(s)
   
Reply
#23
This is getting silly you most read what post.
I can get that error to bye doing File --> Upload Notebook.
This is not what you shall do.
Look at image stay away from the top menu line.
It's the menu on the left side Files,then if you take mouse over Upload it say Upload to session storage.
When Push button it open file menu and you have to navigate to data.json on your hard-drive.
Reply
#24
(Feb-23-2020, 04:50 PM)snippsat Wrote: This is getting silly you most read what post.
I can get that error to bye doing File --> Upload Notebook.
This is not what you shall do.
Look at image stay away from the top menu line.
It's the menu on the left side Files,then if you take mouse over Upload it say Upload to session storage.
When Push button it open file menu and you have to navigate to data.json on your hard-drive.

when trying to select data.json file from menu on left side files,i can not see my data.json file as shon in attached screen shot for uploding were you able to see that data.json file once you had saved it as a notepad++ file on your desktop and once you tried to select it from this option.?
not sure why i am unable to select it whereas the same is available on my deskop in a notepad++ file.

Attached Files

Thumbnail(s)
   
Reply
#25
experts,please advise what is wrong here?

Thanks
Reply
#26
did you bother to look at @snippsat image? He shows with arrow the Upload that you need to use. How you will see the file before you upload it?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#27
(Feb-24-2020, 01:28 PM)buran Wrote: did you bother to look at @snippsat image? He shows with arrow the Upload that you need to use. How you will see the file before you upload it?
in his attached diagram it says first select then upload but for me to select itself file is not getting populated whereas i can see it is there on desktop as a notepad++ file.
Reply
#28
Ohhhhh Doh you have not even done File --> New Notebook still in starting notebook intro.
Shall not select data.json have to upload it as i show with image.
You shall do nothing with the data.json after download other than maybe move to a folder of choice.

Last try here a video Shocked from start to finish.
Reply
#29
(Feb-24-2020, 01:45 PM)snippsat Wrote: Ohhhhh Doh you have not even done File --> New Notebook still in starting notebook intro.
Shall not select data.json have to upload it as i show with image.
You shall do nothing with the data.json after download other than maybe move to a folder of choice.

Last try here a video Shocked from start to finish.

ok,thanks.

but how does it match with my problem,i mean here i have very very complex data model like below:-
Introduction
Someone wants to manage their website. One of
the most important pages on their website is the “Menu” page.The menu gets updated every
night at the restaurant and Joe’s grill wants the updated menu published to their website every
morning. customer will upload their menu in a JSON formatted file (Let’s call it menu.json) to our
ftp server every night.
Requirement is to develop a program to take this menu.json file and store the data
in a relational database. The data model for the database tables is defined as follows.
Data model
items: id(pkey), name
categories: id(pkey), name
category_items: id(pkey), category_id (fkey categories), item_id(fkey items)
menu.json
{
"category”:[{
“name”: “Appetizer”,
},
{
“name”: “Entree”
}
]
],
"item”:[
{
"name":"French Fries",
"category":"Appetizer"
},
{
"name":"Onion Rings",
"category":"Appetizer"
},
{
"name":"Sandwich",
"category":"Entree"
},
{
"name":"Tacos",
"category":"Entree"
},
{
"name":"Ice Cream Sundae",
"category":"Dessert"
}
],
"restaurant":"Joe's Grill"
}
}
Existing classes:
class category:
def __init__(self, name):
self.name = name
class item:
def __init__(self, name, category_name):
self.name = name
self.category_name = category_name
Helper Functions that Already exist
// json.get_categories(file_name) -> returns array of active category objects (category.name)
// json.get_items(file_name) --> returns array of item object (item.name, item.category_name)
// db.write(table_name, <a data dict or an array of data dicts>) //db.write('categories', {'name':
'c1'})
Note:The keys of the dictionary are the table column names, the values are the row values in
the database table
Reply
#30
Use Code Tag,and there is no indentation in code you have posted.
There is mix of two diffent quotation marks in the json sample,that will never work.
"category
jk91 Wrote:but how does it match with my problem,i mean here i have very very complex data model like below:-
You struggle even with the most basic stuff as usage of OS,files...ect,have you looked into and learned some basic Python?
If this is task you have gotten,ask people who have given it you to help get started.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 53 5 hours ago
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 2,784 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  parse json field from csv file lebossejames 4 668 Nov-14-2023, 11:34 PM
Last Post: snippsat
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,308 Nov-09-2023, 10:56 AM
Last Post: mg24
  read file txt on my pc to telegram bot api Tupa 0 1,048 Jul-06-2023, 01:52 AM
Last Post: Tupa
  parse/read from file seperated by dots giovanne 5 1,043 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Formatting a date time string read from a csv file DosAtPython 5 1,161 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  How do I read and write a binary file in Python? blackears 6 6,015 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Python Script to convert Json to CSV file chvsnarayana 8 2,344 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Loop through json file and reset values [SOLVED] AlphaInc 2 1,962 Apr-06-2023, 11:15 AM
Last Post: AlphaInc

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020