How to use Object type in JS scripts?

Dear All,
I need to use JS Object datatype in my scripts like

var data = {};
data.x = 1;
data.y = {"k":"l"};

But when I declare “data” variable, I receive an error

Cannot find serializer for value 'Untyped value '[object Object]''.

Could you please give me any clue on how to work with such datatype inside a script?
Thanks in advance!

looks like you are treating a JS object as a Java object, which it is not.

Just like in a browser where you need to stringify your json, you need to do the same in Nashorn JS.

var data = {};
data.x = 1;
data.y = {"k":"l"};

execution.setVariable('myStringVar', JSON.stringify(data))
execution.setVariable('mySpinVar', S(JSON.stringify(data)))

Good to read the docs for how JS is stored in the java execution: https://www.n-k.de/riding-the-nashorn/#_scriptobjectmirror.

1 Like

Spam. Don’t click.