src/org/ohmage/validator/CampaignValidators.java
public static List<JSONObject> validateUploadedJson(
			final String uploadValue) throws ValidationException {
		LOGGER.info("Validating the uploaded JSON.");

		if(StringUtils.isEmptyOrWhitespaceOnly(uploadValue)) {
			return null;
		}

		JSONArray surveyResponseJson;
		try {
			surveyResponseJson = new JSONArray(uploadValue);
		}
		catch(JSONException e) {
			throw new ValidationException(
					ErrorCode.SERVER_INVALID_JSON,
					"The uploaded JSON was not a JSONArray.",
					"The uploaded JSON was not a JSONArray: " + uploadValue, 
					e);
		}
		int numResponses = surveyResponseJson.length();

		List<JSONObject> result = new ArrayList<JSONObject>(numResponses);

		for(int i = 0; i < numResponses; i++) {
			try {
				result.add(surveyResponseJson.getJSONObject(i));
			}
			catch(JSONException e) {
				throw new ValidationException(
						ErrorCode.SERVER_INVALID_JSON, 
						"One of the survey responses was not valid JSON.", 
						e);
			}
		}

		return result;
	}
/**
	 * Validates that a string uploaded by a client is a valid JSONArray of
	 * JSONObjects. It does no validation of the individual survey responses.
	 * 
	 * @param uploadValue The string uploaded by the client.
	 * 
	 * @return A list of the survey responses as JSONObjects.
	 * 
	 * @throws ValidationException Thrown if the response was not valid JSON.
	 */
Validates that a string uploaded by a client is a valid JSONArray of
JSONObjects. It does no validation of the individual survey responses.

@param uploadValue The string uploaded by the client.

@return A list of the survey responses as JSONObjects.

@throws ValidationException Thrown if the response was not valid JSON.
Validates that a string uploaded by a client is a valid JSONArray of JSONObjects . It does no validation of the individual survey responses . @param uploadValue The string uploaded by the client . @return A list of the survey responses as JSONObjects . @throws ValidationException Thrown if the response was not valid JSON .
public static List<JSONObject> validateUploadedJson(
			final String uploadValue) throws ValidationException {
		LOGGER.info("Validating the uploaded JSON.");
		if(StringUtils.isEmptyOrWhitespaceOnly(uploadValue)) {
			return null;
		}
		JSONArray surveyResponseJson;
		try {
			surveyResponseJson = new JSONArray(uploadValue);
		}
		catch(JSONException e) {
			throw new ValidationException(
					ErrorCode.SERVER_INVALID_JSON,
					"The uploaded JSON was not a JSONArray.",
					"The uploaded JSON was not a JSONArray: " + uploadValue, 
					e);
		}
		int numResponses = surveyResponseJson.length();
		List<JSONObject> result = new ArrayList<JSONObject>(numResponses);
		for(int i = 0; i < numResponses; i++) {
			try {
				result.add(surveyResponseJson.getJSONObject(i));
			}
			catch(JSONException e) {
				throw new ValidationException(
						ErrorCode.SERVER_INVALID_JSON, 
						"One of the survey responses was not valid JSON.", 
						e);
			}
		}
		return result;
	}
public static List < JSONObject > validateUploadedJson ( final String uploadValue ) throws ValidationException { LOGGER . info ( "Validating the uploaded JSON." ) ; if ( StringUtils . isEmptyOrWhitespaceOnly ( uploadValue ) ) { return null ; } JSONArray surveyResponseJson ; try { surveyResponseJson = new JSONArray ( uploadValue ) ; } catch ( JSONException e ) { throw new ValidationException ( ErrorCode . SERVER_INVALID_JSON , "The uploaded JSON was not a JSONArray." , "The uploaded JSON was not a JSONArray: " + uploadValue , e ) ; } int numResponses = surveyResponseJson . length ( ) ; List < JSONObject > result = new ArrayList < JSONObject > ( numResponses ) ; for ( int i = 0 ; i < numResponses ; i ++ ) { try { result . add ( surveyResponseJson . getJSONObject ( i ) ) ; } catch ( JSONException e ) { throw new ValidationException ( ErrorCode . SERVER_INVALID_JSON , "One of the survey responses was not valid JSON." , e ) ; } } return result ; }
Validates that a string uploaded by a client is a valid JSONArray of
 JSONObjects.
Validates that a string uploaded by a client is a valid JSONArray of JSONObjects .