### Question:
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); } }  static JSONObject parse(ReadableMap map); static JSONArray parse(ReadableArray arr);  }### Answer:
@Test public void parsesMap() throws Exception { JavaOnlyMap input = new JavaOnlyMap(); input.putString("keyString", "stringValue"); input.putInt("keyInt", 123); input.putDouble("keyDouble", 123.456); input.putBoolean("keyBoolean", true); input.putArray("keyArray", new JavaOnlyArray()); input.putMap("keyMap", new JavaOnlyMap()); input.putNull("bla"); JSONObject result = JSONParser.parse(input); assertThat(result.keys()).containsOnly( "keyString", "keyInt", "keyDouble", "keyBoolean", "keyMap", "keyArray"); assertThat(result.get("keyString")).isEqualTo("stringValue"); assertThat(result.get("keyInt")).isEqualTo(123); assertThat(result.get("keyDouble")).isEqualTo(123.456); assertThat(result.get("keyBoolean")).isEqualTo(true); assertThat(result.getJSONObject("keyMap").keys()).isEmpty(); assertThat(result.getJSONArray("keyArray").length()).isZero(); }
@Test public void parsesArrays() throws Exception { JavaOnlyArray input = new JavaOnlyArray(); input.pushString("Hello"); input.pushInt(123); input.pushDouble(123.456); input.pushBoolean(true); input.pushArray(new JavaOnlyArray()); input.pushMap(new JavaOnlyMap()); input.pushNull(); JSONArray result = JSONParser.parse(input); assertThat(result.length()).isEqualTo(6); assertThat(result.get(0)).isEqualTo("Hello"); assertThat(result.get(1)).isEqualTo(123); assertThat(result.get(2)).isEqualTo(123.456); assertThat(result.get(3)).isEqualTo(true); assertThat(result.getJSONArray(4).length()).isZero(); assertThat(result.getJSONObject(5).keys()).isEmpty(); }