Complete the code to read JSON test data from a file.
JSONObject jsonObject = new JSONObject(new JSONTokener(new FileReader([1])));The file name must be a string literal, so it needs quotes.
Complete the code to extract a value from JSON test data.
String username = jsonObject.getString([1]);JSON keys must be passed as strings with quotes.
Fix the error in the code to parse JSON test data correctly.
JSONArray users = jsonObject.getJSONArray([1]);The key to get the JSON array must be a string literal with quotes.
Fill both blanks to loop through JSON array and get each user's email.
for (int i = 0; i < users.length(); i++) { JSONObject user = users.getJSONObject([1]); String email = user.getString([2]); }
Use the loop index 'i' to get each JSONObject and the key "email" to get the email string.
Fill all three blanks to create a test data map from JSON keys and values.
Map<String, String> testData = new HashMap<>(); testData.put([1], jsonObject.getString([2])); assertEquals([3], testData.get("username"));
Use the key "username" for both put key and getString key, and assert the expected value "testUser".
