Ticket Created
over 3 years ago

CIQQA-903

Processing JSON with missing root

The following (which is valid JSON) returns  INVALID_HTTP_BODY_IN_NETWORK_RESPONSE.

It's missing the root node but is still valid JSON. Missing the root node is fairy common. So, it should be able to be processed by IQ.

[
{
"name":"aaaa"
},
{
"name":"bbbb"
}
]

The following  is not missing the root node (and works).

 

{
"list" : [
{
"name":"aaaa"
},
{
"name":"bbbb"
}
]
}

  • But of course bug is bug especially that this code

    var d = { "" => "xx"};
    SYS.println(d + " " + d.get(""));

    shows

    {=>xx} xx

    This is not a bug. The output generated by converting a Dictionary to a String is _not_ JSON. It is simple as that.

  • This conversation is all over the place. The original question about the JSON result from a makeWebRequest has been answered.

  • But we have to remember that dictionary isn't any standard outside CIQ and JSON is. In many situation is impossible to change respond because it is external service - nobody will change service just because dictionary.

    So if dictionary key can be empty string I think that during process changing from json to dictionary empty key can be easy added.

  • No one is claiming that it's the same thing.

    The issue is missing the key in the root. Not in other levels.

    It's fairly common to be missing the key at the root. It's common for consumers to deal with it. It's Garmin being odd man out.

    One could even make up a name.

  • > Maybe it's valid json but sdk need name for dictionary key so error...

    Yes. The makeWebRequest functionality requires the incoming JSON to be a JSON Object (a MonkeyC dictionary). This has come up before, several times. We have not changed the behavior thus far, so I have some doubt that we'd change it unless there was a really good motivation.

    > Why can't the key be an empty string?

    The data that doesn't work that is shown above is a JSON Array, and as I've just explained we expect the web service to provide a JSON Object (a Dictionary). A JSON Object with an empty key is *not* the same as a JSON Array. Example..

    # this is a JSON array
    
    [
      {
        "name":"aaaa"
      },
      {
        "name":"bbbb"
      }
    ]
    
    
    # this is a JSON dictionary with an empty string as a key
    {
      "": [
            {
              "name":"aaaa"
            },
            {
              "name":"bbbb"
            }
      ]
    ]
    

    If the incoming JSON is a valid JSON Object (Dictionary), we should be able to process it.