IBMStreams / streamsx.json

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

Add support for auto conversion of numeric values to strings #83

Closed erelsibm closed 6 years ago

erelsibm commented 7 years ago

currently if the user wants to parse a numeric value as string, it is not possible with the current function. this is important for the streaming pipelines use case where the user can define a schema and the system does the casting where possible behind the scenes. the same would apply to boolean values.

ddebrunner commented 7 years ago

Can you be more specific about the context you are talking about, or specifically what you are trying to do?

erelsibm commented 7 years ago

users might want to convert numbers to strings for various reasons, the issue is that if a user has set the field type to be a string in the edit schema widget in streaming pipelines, we will try to parse the field as string, currently what happens when it's a number in the json, it returns an empty string. the desired behavior is to auto convert the number to string representation of the number, same for boolean.

ddebrunner commented 7 years ago

Sorry, I meant using what operator/function. Ie. when you say it returns an empty string what is "it"?

leongor commented 7 years ago

@ddebrunner Lately, I have added native functions (parseJSON, queryJSON) to parse JSON. There is a support to implicitly convert string values to booleans and numbers to handle sloppy JSONs (when everything arrives as strings). This issue is about the opposite case, when strings expected, but JSON values arrive without quotes.

bmel commented 7 years ago

@ddebrunner

Illustrating examples

Social security numbers or zip codes that a pipeline expects to be strings may occur in incoming JSON messages without quotes.

API Background

With the JSON parsing/query API, the type of requested values must be indicated, by way of a default value: "", 0.0, false, ... This is necessary due to the static typing underlying SPL/C++.

Problem

For the examples above, requested values are not returned (or rather: the default empty string is returned) when requesting a value as string, and it is not quoted in JSON (such as SSNs or ZIP codes).

Requested API behavior change

When the requested value type is string and the actual value is not quoted (number, boolean), then the API should internally cast the value and return it as string.

leongor commented 7 years ago

I have a fix for this issue, but I don't want to merge it with the currently open PR: https://github.com/IBMStreams/streamsx.json/pull/85 Once it's merged I'll open a new PR for it.

leongor commented 7 years ago

PR opened: https://github.com/IBMStreams/streamsx.json/pull/88

leongor commented 7 years ago

Merged - can be closed.

rnostream commented 6 years ago

88 merged