makeWebRequest POST with boolean json data : 'True' vs 'true', 'False' vs 'false'

Former Member
Former Member
Connectiq 2.4.3

var options = {
:method => Comm.HTTP_REQUEST_METHOD_POST,
:headers => {
HEADER_APP_ID => APP_ID,
HEADER_CLIENT_KEY => CLIENT_KEY,
HEADER_SESSION_TOKEN => sessionToken,
HEADER_CONTENT_TYPE => Comm.REQUEST_CONTENT_TYPE_JSON
},
:responseType => Comm.HTTP_RESPONSE_CONTENT_TYPE_JSON
};

Comm.makeWebRequest(
url,
params,
options,
method(:onReceive)
);


This works fine when params does not contain boolean values

params = {
"some_key" => "some_value"
}


But fails when params contains boolean values

params = {
"some_key" => true
}


When the boolean value is true, we get 'error 400 {error=>Unexpected token T in JSON at position xyz}' and when the value is false we get 'error 400 {error=>Unexpected token F in JSON at position xyz}'

I'm assuming that the sdk is transforming the values to "True" and "False" instead of "true" and "false" :(
  • Former Member
    Former Member
    Hey,

    I've got this one ticketed. We'll work on getting some solid reproduction steps in place and get something in place. Can you give me a little more info about the issue though? Specifically, is this in the sim or on a device? Is this while using specific mobile platform for communications? Etc. Any more info about the environment would be helpful.

    Thanks,
    - Coleman
  • I just ran into this myself. I have an app that talks to Phillip Hue Lights and it sends over a JSON payload containing light state. The simplest operation is turning a light on.

    I spun up a netcat instance and watched the traffic, here's what I saw:


    $ nc -l 4000

    PUT /api/<key-elided>/lights/1/state HTTP/1.1

    Host: 10.0.1.17:4000

    User-Agent: Mozilla/5.0

    Accept: */*

    Content-Type: application/json

    Content-Length: 11




    {"on":True}


    That capitalized 'True' is causing the Phillips Hue API to return back 'invalid JSON body'. This is in the simulator, with HTTPS secure connections disabled, since Hue doesn't support HTTPS (a whole other issue!).


    Update: Looks like a regression from https://forums.garmin.com/forum/developers/connect-iq/145494-