Python Forum
Json fields not being retrieved
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Json fields not being retrieved
#1
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"
        }
    ]
}
Reply


Messages In This Thread
Json fields not being retrieved - by mrcurious2020 - Sep-14-2020, 12:16 AM
RE: Json fields not being retrieved - by scidam - Sep-14-2020, 12:34 AM
RE: Json fields not being retrieved - by bowlofred - Sep-14-2020, 01:15 AM
RE: Json fields not being retrieved - by bowlofred - Sep-14-2020, 06:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sequential number for rows retrieved and storing the Primary UKey to the line number GYKR 2 584 Aug-22-2023, 10:14 AM
Last Post: GYKR
  Compare fields from two csv files georgebijum 3 1,374 Apr-25-2022, 11:16 PM
Last Post: Pedroski55
  how to filter two fields in json using python python_student 4 3,706 Mar-15-2021, 05:58 PM
Last Post: python_student
  Mapping Fields zak308 0 2,507 Jan-09-2018, 10:02 PM
Last Post: zak308

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020