How can I get AppleScript to run this query and save each value (country, city, etc.) as an AppleScript variable?
http://ip-api.com/json/8.8.8.8?fields=country,city,isp,org,as,mobile,proxy,message
I'm trying to get information about IP and domain and set the value of some variables.
I was not sure how to even run the query from AppleScript so I used do shell script
to call curl
:
set IPAddress to "8.8.8.8"
set link to "http://ip-api.com/json/" & IPAddress & "?fields=country,city,isp,org,as,mobile,proxy,message"
set curl_command to "curl " & link
do shell script curl_command
The result is JSON formatted text. Is AppleScript's text delimiter the only option for parsing the result?
Best Answer
The easiest way is to use JSON Helper app available on the AppStore. Then you simply do something like this:
Result:
"United States"