141k views
0 votes
Write a function named "read_json" that takes a JSON formatted string as a parameter and return the data represented by the input in the appropriate types for this language. For example, if the input string represents a JSON object you should return a key-value store containing the same data?

1 Answer

2 votes

Answer:

Following are the program in the Python Programming Language.

import json #import package

#define function

def read_json(info):

return json.loads(info)#load data in variable

#call and print the function

print(read_json('[{'A': 10}, {'Y': 16}, {'U': 28}]'))

Output:

[{'A': 10}, {'Y': 16}, {'U': 28}]

Step-by-step explanation:

following are the description of the code

  • Define function "read_json()" and pass an argument "info" inside it.
  • Return the data inside from the "load()" function .
  • Call the function i.e "read_json" and passing the value to that function.
  • Print function print the data which is inside the "read_json" function.
User Sfiss
by
6.5k points