Community discussions

MikroTik App
 
xrlls
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 51
Joined: Sun Jan 13, 2019 4:43 pm

Creating array element with type nil

Mon Dec 25, 2023 3:26 pm

Hi,

I am working with the new serialize and deserialize commands for JSON. I found that the deserialize command will convert a null payload to a variable with type nil:
> global org [deserialize value="{\"a\":\"Hi\",\"b\":12,\"c\":null}" from=json ]
> put $org
a=Hi;b=12;c=
> put [typeof ($org->"c")]
nil
This is all good, and makes sense, but if I want to create a JSON payload with an entry with a null payload, how do I create an array element without assigning it any value, and with type nil?
> global new
> set ($new->"a") "Hi"
> set ($new->"b") 12   
> set ($new->"c")   #What goes here?
> put $new
a=Hi;b=12
> put [serialize $new to=json ]
{"a":"Hi","b":12}
Any input is appreciated!
 
optio
Long time Member
Long time Member
Posts: 675
Joined: Mon Dec 26, 2022 2:57 pm

Re: Creating array element with type nil  [SOLVED]

Mon Dec 25, 2023 3:35 pm

> set ($new->"c")   #What goes here?
[:nothing]
 
xrlls
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 51
Joined: Sun Jan 13, 2019 4:43 pm

Re: Creating array element with type nil

Mon Dec 25, 2023 5:32 pm

Thanks! :)

Who is online

Users browsing this forum: No registered users and 12 guests