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"
}
]
}

Parents
  • There are some languages that provide for "automatic" serialization/deserialization between objects and JSON. As far as I understand, you have to provide the code for doing that in Monkey C.

    Yes. We provide that code. That code expects the response body to contain a JSON object, and it converts that JSON object to a MonkeyC Dictionary type.

    That is, a dictionary is not the same as an object.

    I never said that. I specifically used the term JSON object in all of my comments above. I did this intentionally because JSON object has a very specific meaning.

    You can check the definition by reading the ECMA specification [1]. To recap, a JSON object is a collection of zero or more name/value pairs, where the names are always of type String. This means that JSON object is just an associative collection with keys that are strings. It is a formal subset of the dictionary type in many programming languages. In Java, the type org.json.JSONObject extends java.lang.Map<String, JsonObject> [2]. In python, a parsed JSON object is returned as a native dict type.

    The bottom line is that the code that processes the HTTP response body for a JSON request requires that data to represent a JSON object. As such, it must conform to the grammar that describes JSON object [1].

    [1] https://www.ecma-international.org/wp-content/uploads/ECMA-404_2nd_edition_december_2017.pdf
    [
    2] https://docs.oracle.com/javaee/7/api/javax/json/JsonObject.html

Comment
  • There are some languages that provide for "automatic" serialization/deserialization between objects and JSON. As far as I understand, you have to provide the code for doing that in Monkey C.

    Yes. We provide that code. That code expects the response body to contain a JSON object, and it converts that JSON object to a MonkeyC Dictionary type.

    That is, a dictionary is not the same as an object.

    I never said that. I specifically used the term JSON object in all of my comments above. I did this intentionally because JSON object has a very specific meaning.

    You can check the definition by reading the ECMA specification [1]. To recap, a JSON object is a collection of zero or more name/value pairs, where the names are always of type String. This means that JSON object is just an associative collection with keys that are strings. It is a formal subset of the dictionary type in many programming languages. In Java, the type org.json.JSONObject extends java.lang.Map<String, JsonObject> [2]. In python, a parsed JSON object is returned as a native dict type.

    The bottom line is that the code that processes the HTTP response body for a JSON request requires that data to represent a JSON object. As such, it must conform to the grammar that describes JSON object [1].

    [1] https://www.ecma-international.org/wp-content/uploads/ECMA-404_2nd_edition_december_2017.pdf
    [
    2] https://docs.oracle.com/javaee/7/api/javax/json/JsonObject.html

Children
No Data