=mmdblookup Fix GeoIP's ''mmdblookup'' output to make it real json: mmdblookup -f /var/lib/GeoIP/GeoLite2-City.mmdb -i $ip \ | perl -0777 -pe 's/\s+<\w+>$/, /gm; s/([\d"])$/$1,/s; s/\s+/ /g; s/,\s*(})/$1/g; s/}\s*([\d"])/}, $1/g;' \ | jq The regexes are (this can certainly be simplified!) : s/\s+<\w+>$/, /gm; # remove type indicator s/([\d"])$/$1,/s; # add comma after value s/\s+/ /g; # make it all one line s/,\s*(})/$1/g; # remove extra commas s/}\s*([\d"])/}, $1/g; # add missing commas ==See also * https://github.com/mivk/ip-country * https://github.com/maxmind/libmaxminddb/issues/135 * https://github.com/maxmind/libmaxminddb/issues/212