Skip to content

Instantly share code, notes, and snippets.

@glurp
Created March 18, 2010 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glurp/336594 to your computer and use it in GitHub Desktop.
Save glurp/336594 to your computer and use it in GitHub Desktop.
static public Object to_jsonnable(Object o) {
if (o instanceof List) {
List lo = (List)o;
ArrayList nlo = new ArrayList();
for (Object a : lo) nlo.add(to_jsonnable(a)) ;
return(nlo);
} else if (o instanceof Map) {
Map mo = (Map)o;
LinkedHashMap<Object, Object> nmo =
new LinkedHashMap<Object, Object>();
for (Object a : mo.entrySet() ) {
Map.Entry me = (Map.Entry)a;
nmo.put(me.getKey().toString(),to_jsonnable(me.getValue()));
}
return(nmo);
} else if (o instanceof RubyNumeric)
return(o) ;
else
return(o.toString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment