Recent posts:
Recent replies:

I think you will find this is as short as it can possibly go before it starts to become unmaintainable...


fizzbuzz

ii=1:1:100 {
    s i=$tr($t(words+$s(ii#15=0:1,ii#3=0:2,ii#5=0:3,1:4)),"; ")
    i i="ii" i=@i
    w !,i
}

words
    ;;FizzBuzz
    ;;Fizz
    ;;Buzz

    ;;ii
 

Hi Evgeny,

The current GitHub version will only serialise and deserialise to and from class based objects.

I do however have several other solutions in the unofficial version which will efficiently serialise and deserialise to and from globals. I also have a pollyfill solution for DynamicObject and DynamicArray that uses a type mixer class that would allow older versions of Cache to work with these classes now.

However, I've not used these in production, only unit tested. I am happy to release them if there is a need / someone is willing to collaborate on production level testing and debugging.

Hi David,

In general +1 for the generic boiler plate approach.

In terms of a generic JSON solution is could do with some additional type checks to make sure they are output correctly, e.g. booleans as true / false / null, empty numbers being returned as null and not empty string etc.

So just for booleans as an untested example you might replace...

set $PROPERTY(tRow,tColumnName) = $PROPERTY(rSet,tColumnName)


with this..

do tRow.%Set(tColumnName,$PROPERTY(rSet,tColumnName),$Select(tColumn.clientType=16:"boolean",1:""))


The alternative, if just going from SQL to a serialised JSON string could be to just use SQL and JSON_ARRAYAGG as per the examples here...

https://community.intersystems.com/post/how-do-i-return-json-database-sql-call

Open Exchange applications:
Followers:
Following:
Sean has not followed anybody yet.
Global Masters badges: