Is there a way to filter all but a specific number in a curl request result?
Here is the curl what I use in a bash:
curl -X GET "https://api.brightsky.dev/current_weather?lat=51.58&lon=7.38" \
-H "Accept: application/json"
I need only the temperature digit(s) in the result (include - or if any there).
The result looks like this:
{"weather": {"source_id": 42212, "timestamp": "2022-02-04T21:00:00 00:00", "cloud_cover": 100, "condition": "dry", "dew_point": 1.49, "precipitation_10": 0.0, "precipitation_30": 0.0, "precipitation_60": 0.0, "pressure_msl": 1013.8, "relative_humidity": 83, "visibility": 35616, "wind_direction_10": 240, "wind_direction_30": 240, "wind_direction_60": 240, "wind_speed_10": 18.7, "wind_speed_30": 17.6, "wind_speed_60": 16.9, "wind_gust_direction_10": 250, "wind_gust_direction_30": 250, "wind_gust_direction_60": 250, "wind_gust_speed_10": 27.4, "wind_gust_speed_30": 29.5, "wind_gust_speed_60": 31.0, "sunshine_30": 0.0, "sunshine_60": 0.0, "temperature": 4.1, "fallback_source_ids": {"cloud_cover": 11689, "condition": 11689, "pressure_msl": 11689, "visibility": 11689, "wind_direction_10": 11689, "wind_direction_30": 11689, "wind_direction_60": 11689, "wind_speed_10": 11689, "wind_speed_30": 11689, "wind_speed_60": 11689, "wind_gust_direction_10": 11689, "wind_gust_direction_30": 11689, "wind_gust_direction_60": 11689, "wind_gust_speed_10": 11689, "wind_gust_speed_30": 11689, "wind_gust_speed_60": 11689, "sunshine_30": 11689, "sunshine_60": 11689}, "icon": "cloudy"}, "sources": [{"id": 42212, "dwd_station_id": "13696", "observation_type": "synop", "lat": 51.5966, "lon": 7.40484, "height": 60.0, "station_name": "Waltrop-Abdinghof", "wmo_station_id": "H443", "first_record": "2022-02-03T15:30:00 00:00", "last_record": "2022-02-04T21:00:00 00:00", "distance": 2523.0}, {"id": 11689, "dwd_station_id": "01303", "observation_type": "synop", "lat": 51.4041, "lon": 6.96774, "height": 150.0, "station_name": "Essen-Bredeney", "wmo_station_id": "10410", "first_record": "2022-02-03T15:30:00 00:00", "last_record": "2022-02-04T21:00:00 00:00", "distance": 34639.0}]}
CodePudding user response:
With jq:
curl -s ... | jq '.weather.temperature'
Or with python 2.7 and its JSON parser:
curl -s ... | python2.7 -c "import sys, json; print json.load(sys.stdin)['weather']['temperature']"
Output:
4.1
