Below is the code I am running in my Java compiler:
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.put("person", "{name: 'Bob', favoriteColor: 'red'}");
System.out.println(engine.get("person.name"));
I would expect this to evaluate to "Bob", but instead it gives me null
. If I try printing just the user object, it properly gives me this output:
{name: 'Bob', favoriteColor: 'red'}
Why is person.name
evaluating to null
? Any help would be appreciated!