Manipulating JSON with Gron
Poking around with curl trying to do things and found a nice supplemental tool
Say you have curl https://api.weather.gov/points/32.7687,-97.3093
Gives you the big JSON response
{
"@context": [
"https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld",
{
"wx": "https://api.weather.gov/ontology#",
"s": "https://schema.org/",
"geo": "http://www.opengis.net/ont/geosparql#",
...
}
}
Now flatten it with gron
curl https://api.weather.gov/points/32.7687,-97.3093 | gron
Response
json = {};
json.geometry = {};
json.geometry.coordinates = [];
json.geometry.coordinates[0] = -97.309299899999999;
json.geometry.coordinates[1] = 32.768700000000003;
json.geometry.type = "Point";
...
And do some greps on it
curl https://api.weather.gov/points/32.7687,-97.3093 | gron | fgrep "properties.relativeLocation.properties.city"
Response
json.properties.relativeLocation.properties.city = "Fort Worth";
And now reformat the snippet back to JSON
curl https://api.weather.gov/points/32.7687,-97.3093 | gron | fgrep "properties.relativeLocation.properties.city" | gron --ungron
{
"properties": {
"relativeLocation": {
"properties": {
"city": "Fort Worth"
}
}
}
}
Read API responses and make them easier to search for items