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

I am using the JSON procs to generate some json data for the jquery-tokeninput widget.

http://loopj.com/jquery-tokeninput/

This accepts an array of objects {id:"",name:""}

In my case some of the name values also happen to be valid integers. The widget code expects all names to be valid strings so when the JSON ouput looks like this

[{id:12345,name:99999}]

the code fails.

Is there any way to give a hint to the JSON generator to handle this?

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