[FB-16471] system.net.httpClient parses json ints as floats

There is a difference in behavior between the JSON parsing done by the system.net.httpClient() response object and the system.util.jsonDecode() function. In particular, integers are always returned as floats from the system.net.httpClient() response JSON.

The code below, run on Ignition 8.0.11 and 8.0.12, shows how the two different JSON parsing approaches return different types:

client = system.net.httpClient()
response=client.get('https://httpbin.org/anything', data={'int':1}, headers={'accept': 'application/json'})
# prints <type 'float'>
print(type(response.json['json']['int'])) 
# prints <type 'int'>
print(type(system.util.jsonDecode(response.text)['json']['int'])) 

Is this behavior intended? The behavior of system.util.jsonDecode() seems to make more sense. At least for my use-case, it did exactly what I wanted it to.

Will it remain this way?

I’d like to be able to use response.json instead of always having to call system.util.jsonDecode(response.text) but this behavior means I’ll have to add several int() calls in my code to turn several float values into int values.

It may be a good idea to document this difference in behavior so people using system.net.httpClient() aren’t confused by how it parses JSON.


While I’m here, the https://docs.inductiveautomation.com/display/DOC80/system.net.httpClient page is missing the name of the keyword argument data in the JythonHttpClient Methods > Parameters section.

What is shown:

String or Dictionary or byte[] - Data to send in the request. [Optional. Defaults to None.]

What it should be

String or Dictionary or byte[] data - Data to send in the request. [Optional. Defaults to None.]

It doesn’t look intentional to me, but I’ll have to open a ticket so we can investigate the consequences of changing the utility function responsible for this conversion.

Nope, and yeah, it should try to use an integer type if appropriate. We’ll get that fixed.

Fixed, good catch!