Last active
November 28, 2023 23:15
-
-
Save kellyfelkins/06880d6431909debf9af3de36d5c1fb9 to your computer and use it in GitHub Desktop.
Some jq examples to remember
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# These jq scripts were developed to deal with geojson files generated with https://rubygems.org/gems/advance | |
# This adds the filename to the path data and pipes it to less for viewing: | |
jq '. + {source_data: { features: [.source_data.features[] + {file: input_filename}]}}' some_geojson.json | less | |
# This pipes it to a new file: | |
jq '. + {source_data: { features: [.source_data.features[] + {file: input_filename}]}}' some_geojson.json > new_file.json | |
# To extract just the features while adding the filename: | |
jq '{features: [.source_data.features[] + {file: input_filename}]}' some_geojson.json > features.json | |
#To extract tall the other annotations, without the path: | |
jq 'del(.source_data)' some_geojson.json > annotations.json | |
# **filtering** | |
# show only features with a particular name | |
jq -C '.features[] | select(.properties.name == "Golden Gate Heights")' sf_neighborhoods.geojson > golden_gate_heights.json | |
# get the keys | |
jq 'keys' data.json | |
Get the count of items for each key in "dates_data"
% jq '.dates_data | map_values(arrays | length)' response_1689718811520.json
{
"market": 1246,
"MEDIA_SOURCE": 1246,
"PRODUCT": 1246,
"PARENT_SOURCE": 1246,
"FEATURE": 1246,
"GEO_UNIT": 1246,
"CHANNEL": 1246,
"DATE": 1246,
"METRIC_NAME": 1246,
"VALUE": 1246,
"MEDIA_TYPE": 1246
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ jq -s "[.[].out]" telemetry.json | less
take a collection of objects, select the 'out' attribute, return an array of all .out values