Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to read json file
#32
(Feb-24-2020, 07:45 PM)snippsat Wrote: 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.

code (data model used in the problem) with brackets:-
The data model for the database tables is defined as follows.
Data model
[code]
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'})

[code/]
Note:The keys of the dictionary are the table column names, the values are the row values in the database table.

(Feb-25-2020, 04:11 PM)jk91 Wrote:
(Feb-24-2020, 07:45 PM)snippsat Wrote: 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
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.

code (data model used in the problem) with brackets:-
The data model for the database tables is defined as follows.
Data model
[code]
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'})

[code/]
Note:The keys of the dictionary are the table column names, the values are the row values in the database table.

there is a mix of two different quotation marks in the json sample,that will never work.
"category what should it be in a correct way then it might be deliberately so that it hould be a very complex case isn't it?
Reply


Messages In This Thread
how to read json file - by jk91 - Feb-18-2020, 11:48 AM
RE: how to read json file - by Larz60+ - Feb-18-2020, 06:02 PM
RE: how to read json file - by ndc85430 - Feb-18-2020, 06:10 PM
RE: how to read json file - by jk91 - Feb-19-2020, 05:44 AM
RE: how to read json file - by ndc85430 - Feb-19-2020, 06:41 AM
RE: how to read json file - by jk91 - Feb-19-2020, 07:28 AM
RE: how to read json file - by jk91 - Feb-20-2020, 06:17 AM
RE: how to read json file - by jk91 - Feb-20-2020, 09:18 AM
RE: how to read json file - by buran - Feb-20-2020, 09:40 AM
RE: how to read json file - by snippsat - Feb-20-2020, 10:03 AM
RE: how to read json file - by jk91 - Feb-20-2020, 11:20 AM
RE: how to read json file - by snippsat - Feb-20-2020, 12:07 PM
RE: how to read json file - by jk91 - Feb-20-2020, 02:10 PM
RE: how to read json file - by snippsat - Feb-20-2020, 02:38 PM
RE: how to read json file - by jk91 - Feb-23-2020, 06:37 AM
RE: how to read json file - by snippsat - Feb-23-2020, 10:49 AM
RE: how to read json file - by jk91 - Feb-23-2020, 11:03 AM
RE: how to read json file - by snippsat - Feb-23-2020, 12:06 PM
RE: how to read json file - by jk91 - Feb-23-2020, 01:17 PM
RE: how to read json file - by jk91 - Feb-23-2020, 02:24 PM
RE: how to read json file - by snippsat - Feb-23-2020, 03:30 PM
RE: how to read json file - by jk91 - Feb-23-2020, 04:26 PM
RE: how to read json file - by snippsat - Feb-23-2020, 04:50 PM
RE: how to read json file - by jk91 - Feb-24-2020, 11:56 AM
RE: how to read json file - by jk91 - Feb-24-2020, 01:15 PM
RE: how to read json file - by buran - Feb-24-2020, 01:28 PM
RE: how to read json file - by jk91 - Feb-24-2020, 01:38 PM
RE: how to read json file - by snippsat - Feb-24-2020, 01:45 PM
RE: how to read json file - by jk91 - Feb-24-2020, 06:22 PM
RE: how to read json file - by snippsat - Feb-24-2020, 07:45 PM
RE: how to read json file - by jk91 - Feb-25-2020, 04:11 PM
RE: how to read json file - by t4keheart - Feb-25-2020, 02:08 PM
RE: how to read json file - by t4keheart - Feb-25-2020, 06:24 PM
RE: how to read json file - by jk91 - Feb-26-2020, 08:10 AM
RE: how to read json file - by snippsat - Feb-26-2020, 05:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 261 May-03-2024, 07:23 AM
Last Post: Pedroski55
  encrypt data in json file help jacksfrustration 1 295 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 2,963 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  parse json field from csv file lebossejames 4 805 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,588 Nov-09-2023, 10:56 AM
Last Post: mg24
  read file txt on my pc to telegram bot api Tupa 0 1,167 Jul-06-2023, 01:52 AM
Last Post: Tupa
  parse/read from file seperated by dots giovanne 5 1,162 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Formatting a date time string read from a csv file DosAtPython 5 1,398 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  How do I read and write a binary file in Python? blackears 6 7,150 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
  Python Script to convert Json to CSV file chvsnarayana 8 2,616 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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