Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option for selecing an element of the JSON tree #3

Open
pbiering opened this issue Feb 28, 2020 · 5 comments
Open

add option for selecing an element of the JSON tree #3

pbiering opened this issue Feb 28, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@pbiering
Copy link

I don't know how others are thinking about, but having the option to lookup a dedicated element of the JSON treen and return this in a simple output line (optionally with element=value to be used in "eval") would be a great advantage for any script related action to avoid using any sophisticated pipe methods e.g. in Bash to get the value of one element...

@pirate
Copy link

pirate commented Feb 28, 2020

+1 I was about to open the same issue. For people just trying to use this as a one-liner (which is probably >90% of people arriving here), forcing them to dive into the JSON tree with jq or other commands is somewhat cumbersome.

It would be great if the use case of "just get me the raw city, country for this IP" is covered without needing external commands.

$ mmdbinspect -db somedb.mmdb -format '{.city.names.en}, {.country.names.en}' 123.123.123.123
Transylvania, Romania

@horgh
Copy link
Contributor

horgh commented Apr 1, 2020

Thanks for the feedback! Something like you describe sounds useful, although having something flexible enough for all use cases might be a challenge. We could probably expand the examples to cover some more cases as a step in this direction.

@horgh horgh added the enhancement New feature or request label Apr 1, 2020
@motobrowning

This comment was marked as off-topic.

@ravage84
Copy link

In the mindset of "Do One Thing And Do It Well", I think it would suffice to show some examples in the examples section of the README.md on how to extract some common queries using jq and link to the jq tutorials for advanced use cases.

@pbiering
Copy link
Author

In the mindset of "Do One Thing And Do It Well", I think it would suffice to show some examples in the examples section of the README.md on how to extract some common queries using jq and link to the jq tutorials for advanced use cases.

somehow convinced if I compare sniplets extracting the country code from the past (GeoIP v1):

$ geoiplookup -i 1.1.1.1 | awk 'match($0, /GeoIP.*: ([A-Z0-9]+),.*/, a) { print a[1]; exit; }'
AU

with present (GeoIP v2 / MMDB)

$ mmdbinspect --db /var/local/share/GeoIP/GeoLite2-City.mmdb 1.1.1.1 | jq -r '.[].Records[].Record.country.iso_code'
AU

or

$ mmdblookup -f /var/local/share/GeoIP/GeoLite2-City.mmdb --ip 1.1.1.1 country iso_code | awk 'match($0, /.*"([A-Z0-9]+)".*/, a )  { print a[1]; exit; }'
AU

Advertisment: ipv6vcalc can do this in one-shot

$ ipv6calc -q --addr2cc 1.1.1.1
AU

BTW:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

5 participants