Sep-14-2020, 12:16 AM
I am trying to read a json file using the below. I am unable to retrieve values though. I'd appreciate a correction to the code below please.
import json import sys import os content = None with open("s.json", "r") as f: content = list(json.load(f)) #build a list of values of location, name and state: for entry in content: tmp_list = [entry.get('location'), entry.get('name'), entry.get('state')] print(tmp_list) #file:s.json { "environment-sensor": [ { "current-reading": 0, "high-critical-threshold": 0, "high-normal-threshold": 0, "location": "P0", "low-critical-threshold": 0, "low-normal-threshold": 0, "name": "PEM Iout", "sensor-name": "current", "sensor-units": "amperes", "state": "Normal" } ] }