Skip to content

Instantly share code, notes, and snippets.

@loadster
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loadster/192e1a90e51bd03dfdf0 to your computer and use it in GitHub Desktop.
Save loadster/192e1a90e51bd03dfdf0 to your computer and use it in GitHub Desktop.
Validate an array property in a JSON response
// {"books": [
// {"id": 4, "name": "Slaughterhouse Five"},
// {"id": 11, "name": "The Old Man and the Sea"},
// {"id": 25, "name": "Don Quixote"}
// ]}
function validate(response) {
var json = JSON.parse(response.bodyAsString);
return json.books && json.books.length > 0; // Make sure at least one book was returned
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment