CCCPaste

Parse JSON in the Linux Shell - BASH

#get the keys for the output
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r 'keys'
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[]|keys'

#get name
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[].name'
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[].name.first'
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[].name.last'
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[]| (.name|.first + " " + .last)'

#get Date of birth
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[].dob
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[].dob| "Born on " + .date + " and is " + (.age|tostring) + " years old"'

#put it all together
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[]| ("\n"),(.name|.first + " " + .last), (.dob| "Born on " + .date + " and is " + (.age|tostring) + " years old")'

#newline char is not needed
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[]| (""),(.name|.first + " " + .last), (.dob| "Born on " + .date + " and is " + (.age|tostring) + " years old")'

#let's add a title line
wget "https://randomuser.me/api/?results=20" -qO-|jq  -r '.results[]| ("\n=== User Info ==="),(.name|.first + " " + .last), (.dob| "Born on " + .date + " and is " + (.age|tostring) + " years old")'


# Open Street Maps Info for Address
address="656 108th Ave N Naples"
url="https://nominatim.openstreetmap.org/search?q=$address&format=json&polygon=1&addressdetails=1"
wget -qO- "$url"|jq '.[]'
wget -qO- "$url"|jq '.[].address'
wget -qO- "$url"|jq '.[].address.postcode'
wget -qO- "$url"|jq '.[].address|"The ZipCode is: " + .postcode'

# Search for store
q="publix"
url="https://nominatim.openstreetmap.org/search?q=$q&format=json&polygon=1&addressdetails=1"
wget -qO- "$url"|jq '.[]'
wget -qO- "$url"|jq '.[].display_name'
wget -qO- "$url"|jq '.[].address.county'

q="publix naples fl"
url="https://nominatim.openstreetmap.org/search?q=$q&format=json&polygon=1&addressdetails=1"
wget -qO- "$url"|jq '.[]'
wget -qO- "$url"|jq '.[].display_name'
wget -qO- "$url"|jq '.[].address.county'

q="publix collier county"
url="https://nominatim.openstreetmap.org/search?q=$q&format=json&polygon=1&addressdetails=1"
wget -qO- "$url"|jq '.[]'
wget -qO- "$url"|jq '.[].display_name'
wget -qO- "$url"|jq '.[].address.county'