Skip to content

Instantly share code, notes, and snippets.

@tanyagupta
Last active November 4, 2016 17:20
Show Gist options
  • Save tanyagupta/33aa2692d130a0c5bec8c91502c11c1e to your computer and use it in GitHub Desktop.
Save tanyagupta/33aa2692d130a0c5bec8c91502c11c1e to your computer and use it in GitHub Desktop.
Accessing heterogenous JSON data (inefficient way) - Part 1
//Note that this is an INEFFICIENT way to solve the problem
function noob_way() {
// get test data from a test data utility
var cars=get_data_set("basic");
for (var i in cars){
if(cars[i]["model"]!==undefined) {
Logger.log(cars[i]["model"]); // Logger.log() is Google App Script's console.log
}
if(cars[i]["trim"]!==undefined) {
Logger.log(cars[i]["trim"]); // Logger.log() is Google App Script's console.log
}
if(cars[i]["year"]!==undefined) {
Logger.log(cars[i]["year"]); // Logger.log() is Google App Script's console.log
}
if(cars[i]["wheel"]!==undefined) {
Logger.log(cars[i]["wheel"]);
if(cars[i]["wheel"]["wheel_size"]!==undefined){
Logger.log(cars[i]["wheel"]["wheel_size"]); // Logger.log() is Google App Script's console.log
}
if(cars[i]["wheel"]["wheel_metal"]!==undefined){
Logger.log(cars[i]["wheel"]["wheel_metal"]); // Logger.log() is Google App Script's console.log
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment