Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this tutorial, you will create a simple JSON parsing module called jsonparser.py JSON is a human-readable file format that consists of key/value pairs. For

image text in transcribed

For this tutorial, you will create a simple JSON parsing module called jsonparser.py JSON is a human-readable file format that consists of key/value pairs. For the purposes of this tutorial, we will assume that all JSON strings follow the form below (the number of key/value pairs can vary) key1 : value1","key2":'value2","keyn:"valuen" More precisely: 1. Each JSON string will begin with a ( 2. Each JSON string will end with a) 3. Each JSON string will have some number of key/value pairs, each of which is separated by a comma 4. Each matching key and value in a JSON string will be separated by a colon 5. The individual keys and values in a JSON string are enclosed within double quotation marks 6. There will be no empty spaces outside of the double-quotation marks JSON also supports arrays but we will not consider them within this tutorial. Problem 1 (JSON to List) Write a function called jsontolist(string) that accepts a string argument that will have the JSON format specified above. You can assume any string your furction will be given has the proper format. This function must use string and list operations to extract each key/value pair and return them in a 2D list. For example, if the JSON string is (firstname":"dave","lastname"."mckenney" "position" "instructor The function should return a 2D list that looks like I ['firstname", "dave"], ["lastname", "mckenney"l, ['position", "instructor']] Each element in the returned list is a list with two elements corresponding to a key and its matching value. Several JSON strings and their corresponding lists are included at the end of the tutorial document so you can check your function before proceeding. Problem 2 (Retrieving Values) Write a second function called getvaluejsonlist, key) that accepts two arguments: a 2D JSON list in the format returned by the function in Problem 1, and a string/key specifying the key you want to retrieve the value for. This function should iterate through the list to find the matching key and return the corresponding value. If no items within

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases In Networked Information Systems 6th International Workshop Dnis 2010 Aizu Wakamatsu Japan March 2010 Proceedings Lncs 5999

Authors: Shinji Kikuchi ,Shelly Sachdeva ,Subhash Bhalla

2010th Edition

3642120377, 978-3642120374

More Books

Students also viewed these Databases questions

Question

2. How does communication shape cultures and social communities?

Answered: 1 week ago

Question

1. Television more Over watching faceing of many problems ?

Answered: 1 week ago

Question

Is there a link between chronic stress and memory function?

Answered: 1 week ago

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago