Last active
August 29, 2015 14:02
-
-
Save loadster/192e1a90e51bd03dfdf0 to your computer and use it in GitHub Desktop.
Validate an array property in a JSON response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// {"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