Forum OpenACS Development: Re: JSON procs, creating objects with numeric values as strings

Dave,

My thoughts probably aren't going to add much value for you of all people, but I looked through the code and there doesn't seem to be a way to force a datatype.

I guess the problem is that as tcl represents everything as a string, there is no preservation of datatype in the tcl layer unless you apply it explicitly, even if the database has the value correctly typed to start with.

The json procs seem to use a regexp to determine datatype, and put simply, if all chars are [0-9] it doesn't wrap in quotes. This seems to me to be an unsafe assumption since the way tcl works is that everything is a string unless you pass it to [expr ], in which case it momentarily treats it as a number and returns a string representation of the answer!

Can't think of an elegant workaround that wouldn't be prone to problems (i.e. prefix with +\b or \0 or something). Maybe the json procs should be modified to treat integers without a decimal point as strings unless followed by 'e0', so for example 7384 becomes 7384e0.

Richard