Question: Hello, I need help with this Python 3.x problem. Any help would be appriciated. Create a simple JSON parsing module called jsonparser.py. We will assume
Hello, I need help with this Python 3.x problem. Any help would be appriciated.
Create a simple JSON parsing module called jsonparser.py. 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}

We will write our first function called jsontolist(string) that accepts a string argument that will have the JSON format specified above. You can assume any string your function 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:

Our Second function called getvalue(jsonlist, 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 the given list match (i.e., the key does not exist), the function should return an empty string. As an example, if you saved the list from jsontolist(string) - above, into a variable called mylist, the output of the getvalue function would be:

For our third function, we need to Write a function called setvalue(jsonlist, key, newvalue) that accepts three arguments: a 2D JSON list in the format returned by the function in out first function jsontolist(string), a string/key specifying the key you want to set the value for, and a string/value that should represents the new value for the given key. For example, if you had the same mylist variable from our second function, getvalue(jsonlist, key), and you executed setvalue(mylist, position, president), mylist would then look like:
[ [firstname, dave], [lastname, mckenney], [position, president] ]
For our last function, Write a function called listtojson(jsonlist) that accepts a 2D list argument in the same format that has been used in the previous problems. The function must return a JSONformatted string that contains the key/value pairs in the 2D list. For example, if you executed listtojson(mylist) using the modified list from function above setvalue(jsonlist, key, newvalue) , your function should return the following string:
{"firstname":"dave","lastname":"mckenney","position":"president"}
More precisely: 1. Each JSON string will begin with a f 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 quotatiorn 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
