On Apr 7, 9:54 am, Joran <[email protected]> wrote: > Hi, I would like to use Prototype's isJSON() to test for valid JSON > strings before eval'ing them. For strings around 244kb in size, this > is tremendously slow, around 200 seconds, shooting the process' CPU > utilization right up to 97% from 0.1% for the same duration. > > The method looks like this: > > isJSON: function() { > var str = this; > if (str.blank()) return false; > str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''); > return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str); > > } > > Your help would be much appreciated. Thanks in advance!
Hi Joran, Out system uses a lot of JSON. We took the JSON parser from here: http://www.json.org/java/ And altered to return instances of ScriptableObject. This seems to work pretty well, and it's very fast. I can try to find a way to post this code if you think it would be helpful, or may find it easiest to just port it yourself, since it's pretty simple. A _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
