Skip to content

Instantly share code, notes, and snippets.

@rgoulter
Created December 1, 2013 17:03
Show Gist options
  • Save rgoulter/7736768 to your computer and use it in GitHub Desktop.
Save rgoulter/7736768 to your computer and use it in GitHub Desktop.
Java, Reading Basic JSON
private static Map mapFromJSON(String json) throws ScriptException{
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.eval("var s = " + json);
return ((Map)engine.eval("s;"));
}
@rgoulter
Copy link
Author

rgoulter commented Dec 1, 2013

@rgoulter
Copy link
Author

rgoulter commented Dec 1, 2013

Also. Not saying I'm proud of this (or that this is a good way to do it).
Just demonstrating how cheaply one can use Java's ScriptEngine to read JSON content (if you know what the JSON should be).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment