197k views
5 votes
Write a function named "json_filter" that takes a JSON formatted string as a parameter in the format of an array of objects where each object has keys "mass", "density", "temperature", and "velocity" and each key maps to a floating point number. This function should return the input as a JSON string in the same format but with only the objects with velocity greater than 38.46

User Dodgrile
by
5.6k points

1 Answer

2 votes

Answer:

Check the explanation

Step-by-step explanation:

kindly check the well written code below to get the solution to your question.

import json

def json_filter(input_string):

jsonFormat = json.loads(input_string)

result = []

for obj in jsonFormat:

if obj["temperature"] > 38.46:

result.append(obj)

return json.dumps(result)

User Dubes
by
4.5k points