IBMStreams / streamsx.json

Toolkit for working with JSON in SPL applications.
http://ibmstreams.github.io/streamsx.json/
Other
3 stars 19 forks source link

Parse numbers into 'decimal' types #92

Closed bmel closed 6 years ago

bmel commented 7 years ago

Currently, in terms of extracting numbers from JSON, only int and float types are supported. When I need to extract numbers from JSON into decimal types without precision loss, I need to work around by requesting the number value as a string and then casting it to value of a decimal type. In order to not cause a cast exception, I need to first try and extract the value as a float. This clutters my code and requires me to call queryJSON() twice, as in this example:

outTuple.lat = queryJSON("/lat", 0.0, status, JsonIndex._1);
if (outTuple.lat != 0.0) { 
    outTuple.lat = (decimal64) queryJSON("/lat", "", status, JsonIndex._1); 
}

Instead, I would like to be able to replace all this by simply calling:

outTuple.lat = queryJSON("/lat", 0.0d, status, JsonIndex._1); 
leongor commented 7 years ago

Fixed as part of this PR: https://github.com/IBMStreams/streamsx.json/pull/91

rnostream commented 6 years ago

91 merged