JS-Interpreter JSON Demo

Moving primitive values (numbers, strings, booleans, etc) in and out of the interpreter is easy, just use interpreter.createPrimitive(value) to wrap a JS primitive into an interpreter's primitive, and value.valueOf() to extract a JS primitive from an interpreter's primitive (or use value.toString(), value.toNumber(), or value.toBoolean() to coerce specific types).

By contrast, moving objects in and out of the interpreter is not advised. Having two JavaScript environments with handles to the same mutable JS object would be problematic. As a result, the best way to move objects (including arrays) in and out of the interpreter is to serialize and deserialize them as JSON. Below is a minimal example of round-tripping a JSON object though the interperter and back.

Click Parse, then either click Step repeatedly, or click Run once. Open your browser's console for errors.


JSON Input:

JSON Output:

Back to the JS-Interpreter documentation.