Error using using global.JSON.stringify() in scoped application - 'Evaluator.evaluateString() problem: java.lang.ClassCastException:'

jarethdisley
Kilo Contributor

I am getting this error 'Evaluator.evaluateString() problem: java.lang.ClassCastException:' when using global.JSON.stringify() in a scoped application - Any ideas why?

In my opinion JSON.stringify should work for any valid Javascript object - Is this not the case?

1 ACCEPTED SOLUTION

I tried it on Helsinki with no issues. Helsinki uses ECMAScript5 by default and may be more resilient to this sort of thing. If you have upgraded to Helsinki, your app is likely still using ES3. You can change it on the app settings.



I tried your simple script in Geneva and it kept failing with a numeric object property name (1). As soon as I changed it to 'a', it worked fine. That's what leads me to believe this is an ES3 vs ES5 thing.


View solution in original post

11 REPLIES 11

cameronrichard
ServiceNow Employee
ServiceNow Employee

Hello Jareth,



JSON.stringify does work in scoped applications. I tested this in both an application scope and global (in Scripts - Background):


var ddd = {


      "test": "value"


};



gs.info(global.JSON.stringify(ddd));



Are you to post the JSON you're trying to stringify?



Thanks,



Cameron


Thank you for your response, I seem to be having a specific issue with numeric keys...



As an example the following fails:



var objectTest = {}


objectTest["1"] = 'hello';


gs.info(global.JSON.stringify(objectTest));



It seems that numeric indexes - Even if they are enclosed within a string are still treated as numeric?


Are you running on Geneva or Helsinki? I want to ensure I'm running on the same release.



I've run this locally and it works as expected. My output:


        sn_sc: {"1":"hello"}


I have tried on both Geneva and Helsinki with the same result.. can you try running in a scope other than 'global'? This seems to work in global but not within a scoped app..