class JSONParser {

    public static JSONObject parse(ReadableMap map) {
        try {
            ReadableMapKeySetIterator it = map.keySetIterator();
            JSONObject result = new JSONObject();
            while (it.hasNextKey()) {
                String key = it.nextKey();
                switch (map.getType(key)) {
                    case String:
                        result.put(key, map.getString(key));
                        break;
                    case Number:
                        result.put(key, parseNumber(map, key));
                        break;
                    case Boolean:
                        result.put(key, map.getBoolean(key));
                        break;
                    case Array:
                        result.put(key, parse(map.getArray(key)));
                        break;
                    case Map:
                        result.put(key, parse(map.getMap(key)));
                        break;
                    default:
                        break;
                }
            }
            return result;
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }

}