I have a specific issue.
i am downloading some data with /tool fetch command
Thecontent of that file is in correct Mikrotik array format, but when i load it into a variable, it is not recognised as an array, but as an ordinary string instead.
:toarray transforms this string into an array with a single element, which is the complete string.
file contents: {"A"="1";"B"="test";"C"="20";"D"="test2";}
Code: Select all
:global data [/file get "file.txt" contents]
:put $data
{"A"="1";"B"="test";"C"="20";"D"="test2";}
:put [:typeof $data ]
str
:put [:toarray $data ]
"A"="1";"B"="test";"C"="20";"D"="test2";
:put ([:toarray $data ]->0)
"A"="1";"B"="test";"C"="20";"D"="test2";
:put ([:toarray $data ]->1)
(empty)
:put ([:toarray $data ]->"A")
(empty)
Code: Select all
:global data {"A"="1";"B"="test";"C"="20";"D"="test2";}
:put [:typeof $data]
array
:put ($data->"A")
1
:put ($data->"B")
test
Code: Select all
/file set test1 contents="{\"A\"=\"1\";\"B\"=\"test\";\"C\"=\"20\";\"D\"=\"test2\";}"
{"A"="1";"B"="test";"C"="20";"D"="test2";}
Code: Select all
:global data {"A"="1";"B"="test";"C"="20";"D"="test2";}
/file set test123 contents=$data
A=1;B=test;C=20;D=test2
Only data directly pasted into the terminal is properly parsed, anything loaded from the file fails.
Essentially, i want some key->value stored, and read to be used in the script.
Any ideas?
Thanks