I found many things about converting Groovy to JSON, but oddly enough, not the other way.
What is the (best) JSON to Groovy parser around there ?
JSON-lib claims to be able to transform POGO to JSON and back. If POGO means what I think it does (Plain Old Groovy Object), you're set :).
They give this example:
def strAsJsonObject = "{integer:1, bool: true}" as JSONObject
Update:
I've tried the lib myself, this is the complete code:
import net.sf.*;
import net.sf.json.*;
import net.sf.json.groovy.*;
println "hi"
GJson.enhanceClasses()
def strAsJsonObject = "{integer:1, bool: true}" as JSONObject
println strAsJsonObject
It'll chase you through a marathon of downloading dependencies (ezmorph, commons lang, commons logger) and once you've resolved them all, this is what you get:
Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '{integer:1, bool: true}' with class 'java.lang.String' to class 'net.sf.json.JSONObject'
According to The mailing list, you get this for not calling GJsonlib.enhanceClasses(), but I did call that, as you can see above.
I've concluded that it's a worthwhile endeavor to hate Groovy's JSON-lib.