public static Object escape(Object original) {
        if (original instanceof Character) {
            char u = (char) ((Character)original);
            int idx = "\b\t\n\f\r\"\'\\".indexOf(u);
            if (idx >= 0)
                return "\\"+"btnfr\"\'\\".charAt(idx);
            if (u < 32) 
                return "\\"+Integer.toOctalString(u);
            if (u > 126) 
                return "\\u"+String.format("%04X", (int)u);
            return original;
        }
        else if (original instanceof String) {
            StringBuilder result = new StringBuilder();
            for (char c : ((String)original).toCharArray())
                result.append(escape(c));
            return "\"" + result.toString() + "\"";
        }
        else if (original.getClass().isArray()) {
            StringBuilder result = new StringBuilder("[");
            int len = Array.getLength(original);
            for (int i=0; i<len; i++)
                result.append(" ").append(escape(Array.get(original, i)));
            return result.append("]").toString();
        }
        return original;
    }