Community discussions

MikroTik App
 
User avatar
Lokamaya
newbie
Topic Author
Posts: 46
Joined: Thu Nov 11, 2021 4:40 am
Location: Bandung

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

Thu Sep 22, 2022 5:33 pm

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 :shock:

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

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

:log warning $parsedIP;
}

Thanks in advance
You do not have the required permissions to view the files attached to this post.
 
User avatar
Lokamaya
newbie
Topic Author
Posts: 46
Joined: Thu Nov 11, 2021 4:40 am
Location: Bandung

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

Thu Sep 22, 2022 5:40 pm

I have run the script and make JSONLoad as global variable.
Thanks
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

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

Thu Sep 22, 2022 7:57 pm

Too much frills and mess....
:global JSONLoad
:log warning ([$JSONLoad "ipaddress-api.json"]->"ip")
 
User avatar
Lokamaya
newbie
Topic Author
Posts: 46
Joined: Thu Nov 11, 2021 4:40 am
Location: Bandung

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

Fri Sep 23, 2022 6:29 am

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: How can I Get/Set Variable from JSON Parse Function?  [SOLVED]

Fri Sep 23, 2022 10:52 am

" 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.
 
User avatar
Lokamaya
newbie
Topic Author
Posts: 46
Joined: Thu Nov 11, 2021 4:40 am
Location: Bandung

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

Sat Sep 24, 2022 9:41 am

Thanks again. This is what I need.
I'am currently using ipinfo.io (json format) to get dynamic public ip.
 
User avatar
elcapitan
just joined
Posts: 1
Joined: Wed Dec 20, 2023 11:04 am

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

Wed Dec 20, 2023 11:14 am

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

Who is online

Users browsing this forum: JDF, UkRainUa and 27 guests