if (x instanceof JSONObject) {
JSONObject theObject = (JSONObject)x;
// Sort the keys
TreeSet<String> t = new TreeSet<String>();
Iterator<?> i = theObject.keys();
while (i.hasNext()) t.add(i.next().toString());
Iterator<String> keys = t.iterator();
StringBuffer sb = new StringBuffer("{");
while (keys.hasNext()) {