How to Read line by line from a file using a script?

Hello, I am trying to follow a very similar script for a very similar task. The main differences are

  • the blacklist.txt is already on the MikroTik,
  • the size of the file (2,6 Mo) doesn’t permit using /file get contents so I use /file read from that script thanks to @anserk .

The blacklist.txt file is made of IP addresses separated with \n and without any non-WAN address:

100.0.71.9
100.10.72.114
100.1.108.246
100.11.124.173
100.1.119.41
100.1.181.84
100.11.94.80
100.1.214.89
100.12.25.11
100.1.32.138
...

I fail with message invalid json (:deserialize; line 20). Here is my script.

:local fname blacklist.txt
:local fsize [/file/get $fname size]
:local max 32768
:local addressListName Blacklist
:local var {""}

# Get the number of chunks minus one since the first offset is 0.
:local chunks (($fsize / $max) - 1)
# If there is a remainder, add another chunk.
: if ($fsize > ($max * $chunks)) do={ :set $chunks ($chunks + 1) }

:for i from=0 to=$chunks do={
  # Start each read from the next chunk
  :local offset ($i * $max)
  :local filechunk [/file/read file=$fname offset=$offset chunk-size=$max as-value]
  :set ($var->0) (($var->0) . ($filechunk->"data"))
}

# Insert to blacklist
:foreach ip in=[:deserialize $var delimiter="\n" from=dsv options=dsv.plain] do={
    :put $ip
    /ip firewall address-list add list=$addressListName address=$ip
}