How can I Get/Set Variable from JSON Parse Function?

Hi all,

I have a json file with IP address and other data. I try to parse it with JParseFunctions (https://github.com/Winand/mikrotik-json-parser). The script running well on terminal, but I don’t know how to make it works on /System/Scripts.
Capture.JPG
JSON code

{
  "ip": "108.177.16.30",
  "hostname": "30.r1.unverified-forwarding.1e100.net",
  "city": "Brussels",
  "region": "Brussels Capital",
  "country": "BE",
  "loc": "50.8505,4.3488",
  "org": "AS15169 Google LLC",
  "postal": "1000",
  "timezone": "Europe/Brussels"
}



My script :open_mouth:


{
:global JSONLoad;
:global parsedIP "X";

:set parsedIP {
    return (:put ([$JSONLoad "ipaddress-api.json"]->"ip"))
}

:log warning $parsedIP;
}

Thanks in advance

I have run the script and make JSONLoad as global variable.
Thanks

Too much frills and mess…

:global JSONLoad
:log warning ([$JSONLoad "ipaddress-api.json"]->"ip")

Thanks @rextended, its works.

I’ll try it with more complex script to get dynamic public IP of my ISP and stored it on address list.

" get dynamic public IP of my ISP and stored it on address list"

All this for simply that? Ignoring the existence of MikroTik’s Cloud DDNS:

/ip firewall address-list
remove [find where list="current-wan-ip"]
add list="current-wan-ip" address=[:resolve "myip.opendns.com" server=208.67.222.222]

Is better you expose what you want at the end, that ask for solve something inside.
If I misunderstood your description, explain yourself better, even with an example.

Thanks again. This is what I need.
I’am currently using ipinfo.io (json format) to get dynamic public ip.

Public IP is also available as text by this link https://ipinfo.io/ip