mahmoud / glom

☄️ Python's nested data operator (and CLI), for all your declarative restructuring needs. Got data? Glom it! ☄️
https://glom.readthedocs.io
Other
1.89k stars 61 forks source link

Can't seem to read a 3rd level #209

Open andrewwclayton opened 3 years ago

andrewwclayton commented 3 years ago

Hi I'm new to Glom an Python so this may be a rookie mistake. I'm trying to print a value from tier 3 of this dictionary which is created from an API.

I can read values from keys in the 2nd level but not the third. I feel like I'm doing it right from reading the documents but I'm not getting the result I need.

Any input would be much appreciated.

I have listed the code below.

import json import requests import time from bs4 import BeautifulSoup from nested_lookup import nested_lookup from glom import glom as glom from glom import Coalesce from glom import glom, Path from glom import glom, Inspect import pprint

baseURL = "http://environment.data.gov.uk/flood-monitoring/id/stations/" stationId = "F1806"

test for connection

response = requests.get(baseURL + stationId) print() print("=======================") print("Server Status - " + str(response.status_code)) print() print("Read JSON Data") print() parsed_json = (response.json()) print(json.dumps(parsed_json, indent=4, sort_keys=True)) print("=======================")

print()

Create Glomspec

print(glom(parsed_json, ('items.measures',['label']))) print() print(glom(parsed_json, Path('items.measures.latestReading',['value'])))