Answered step by step
Verified Expert Solution
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
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started