Use javascript object containing functions as string in nashorn

12 Views Asked by At

I am having some issue using a js object received as string in a variable and use it in nashorn.

Example:

string_obj = '{ title: "book", content: function () { return "123"; } }'

I want to load that string so that I can use it as a standard object.

For example, I want to do this but having my object as string.

/*
var obj = { title: "book",
        content: function () { 
           return "123";
        }
};
*/
var obj = convert_my_string_to_object(string_obj); //how to do that?
var output = Writer.load(param1, obj);

Eval is not working, I am getting an exception as such :

javax.script.ScriptException: SyntaxError: <eval>#582:8<eval>:1:20 Expected ; but found :

Any idea?

0

There are 0 best solutions below