IBMStreams / streamsx.json

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

Doesn't return nested JSON object? #119

Closed GilbertLS closed 3 years ago

GilbertLS commented 4 years ago

Example: { a: { b: 1 } }

queryJSON("/a", "", JsonIndex._1) returns ""

Is this the intended behaviour? I would expect it to return a json string. "{\"b\":1}"

Thanks

rnostream commented 4 years ago

Hi, these queryJSON() functions are designed to read values from a JSON object and assign them to attributes of supported SPL types. There is no SPL type like "JSON object" what would be the return type you would need here. But you can assign the query to a SPL map<rstring, int32> type attribute where you would get back one map element with key:"b" and value: 1. I think this should work.

If you want a string you can only read a JSON value string. Getting back a JSON object was no requirement as the input JSON string is already parsed and you can get all values out of it which you need. The only way of getting an JSON object is that of using SPL map<>. But here all values need to be of same type for any contained JSON attribute.

GilbertLS commented 4 years ago

I was expecting to get back the whole object as a string like this https://github.com/IBMStreams/streamsx.json/pull/120/files#diff-13807cd2ecfde2a68c128b5679a0d9c1R1083

A map wouldn't work for my use case unfortunately the values would not all be of the same type.

rnostream commented 4 years ago

We consider to include this depending on workload. The solution will be probably different to the PR, as users expect the function just to work as it does. So may be different function will be introduced.

rnostream commented 3 years ago

Close this now as Python topology supports all types of JSON scenarios one can imagine and convert into legacy Streams schemas or handle JSON/Python objects transparently in down-stream Python operators.