Python Forum
Need help Understanding JSON
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help Understanding JSON
#2
Please post your code and the entire error message. It is impossible to know what your error is if we cannot see the code that generates the error.
If you do something like this:
data = json.load(json_filename)
data will be a list of dictionaries. Each of these dictionaries has keys for "kind" and "entries". data[index].entries is another list of dictionaries. Each of these dictionaries has keys "date", "url", "description", "inbound", "outbound".

I wrote a little program to load your json as a string (use loads instead of load). There is are errors in the json you posted. These must be cut and paste errors, otherwise you would be getting JSONDecoderErrors.
import json

json_str = """
[
{
"kind": "Symantec Endpoint Protection client/ Symantec Agent",
"entries": [
{
"date": "2021-06-14",
"url": "https://liveupdate.symantec.com",
"description": "Agent Installation Package",
"inbound": false,
"outbound": true
},
{
"date": "2021-06-14",
"url": "https://liveupdate.symantecliveupdate.com",
"description": "Agent Installation Package",
"inbound": false,
"outbound": true
},
{
"date": "2021-06-14",
"url": "https://ent-shasta-rrs.symantec.com",
"description": "Symantec reputation servers",
"inbound": false,
"outbound": true
}
]
},
{
"kind": "Additional Entries for Cloud Managed/ Hybrid managed Agents",
"entries": [
{
"date": "2021-06-14",
"url": "https://usea1.r3.securitycloud.symantec.com",
"description": "Symantec Cloud API gateway",
"inbound": false,
"outbound": true
},
{
"date": "2021-06-14",
"url": "https://us.spoc.securitycloud.symantec.com",
"description": "Cloud notification service (SPOC)",
"inbound": false,
"outbound": true
},
{
"date": "2021-06-14",
"url": "https://storage.googleapis.com",
"description": "Cloud storage services, Live Shell",
"inbound": false,
"outbound": true
},
{
"date": "2021-06-14",
"url": "https://ws.securitycloud.symantec.com",
"description": "Live Shell",
"inbound": false,
"outbound": true
},
{
"date": "2021-06-14",
"url": "https://bds.securitycloud.symantec.com",
"description": "Live Shell",
"inbound": false,
"outbound": true
}
]
}
]
"""

data = json.loads(json_str)
print(type(data), len(data))
print(type(data[0]), list(data[0].keys()))
print(type(data[0]["kind"]), type(data[0]["entries"]))
print(type(data[0]["entries"][0]), list(data[0]["entries"][0].keys()))
print(data[0]["entries"][0])
print(type(data[0]["entries"][0]["outbound"]), data[0]["entries"][0]["outbound"])
Output:
<class 'list'> 2 <class 'dict'> ['kind', 'entries'] <class 'str'> <class 'list'> <class 'dict'> ['date', 'url', 'description', 'inbound', 'outbound'] {'date': '2021-06-14', 'url': 'https://liveupdate.symantec.com', 'description': 'Agent Installation Package', 'inbound': False, 'outbound': True} <class 'bool'> True
Reply


Messages In This Thread
Need help Understanding JSON - by quarinteen - Aug-15-2022, 01:29 PM
RE: Need help Understanding JSON - by deanhystad - Aug-15-2022, 02:48 PM
RE: Need help Understanding JSON - by quarinteen - Aug-15-2022, 04:27 PM
RE: Need help Understanding JSON - by deanhystad - Aug-15-2022, 08:33 PM

Forum Jump:

User Panel Messages

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