I am currently testing REST commands with the API of a UNIFI network controller. In order to modify part of its configuration, I needed to change a JSON value of boolean type. I created a structure to accommodate the modifications, but I encountered problems when I wanted to send the content of my boolean variable. The controller did not accept the value I was sending. In the code below, you can see that the variable "mac_filter_enabled" was tested as both an integer and a string type, but that did not work. I had to create the payload manually by specifying true or false without it being considered a string.
Is this normal?
Could I have done it differently?
Does the problem come from the controller, which should understand that 1 or 0 in this variable corresponds to true or false?
Thank you in advance for the clarification.
Code: Select all
; NON FUNCTIONAL PAYLOAD
Structure macfilter1
mac_filter_enabled.s ; <- boolean type variable STRING
mac_filter_policy.s
List mac_filter_list.s()
EndStructure
Define PutData1.macfilter1
PutData1\mac_filter_enabled = "true"
PutData1\mac_filter_policy = "deny"
AddElement(PutData1\mac_filter_list())
PutData1\mac_filter_list() = "AA:BB:CC:DD:EE:FF"
If CreateJSON(0)
InsertJSONStructure(JSONValue(0), @PutData1, macfilter1)
JASON_Payload1$ = ComposeJSON(0)
FreeJSON(0)
EndIf
Debug JASON_Payload1$
; NON FUNCTIONAL PAYLOAD
Structure macfilter2
mac_filter_enabled.i ; <- boolean type variable INTEGER
mac_filter_policy.s
List mac_filter_list.s()
EndStructure
Define PutData2.macfilter2
PutData2\mac_filter_enabled = #True
PutData2\mac_filter_policy = "deny"
AddElement(PutData2\mac_filter_list())
PutData2\mac_filter_list() = "AA:BB:CC:DD:EE:FF"
If CreateJSON(0)
InsertJSONStructure(JSONValue(0), @PutData2, macfilter2)
JASON_Payload2$ = ComposeJSON(0)
FreeJSON(0)
EndIf
Debug JASON_Payload2$
; FUNCTIONAL PAYLOAD
Expected_JASON_Payload$ = "{" +
#DQUOTE$ + "mac_filter_enabled" + #DQUOTE$ + ":" + "true" + ", " + ; <- boolean type
#DQUOTE$ + "mac_filter_policy" + #DQUOTE$ + ":" + #DQUOTE$ + "deny" + #DQUOTE$ + ", " +
#DQUOTE$ + "mac_filter_list" + #DQUOTE$ + ": [" +
#DQUOTE$ + "01:02:03:04:05:06" + #DQUOTE$ +
"]" +
"}"
Debug Expected_JASON_Payload$
