Skip to content

Instantly share code, notes, and snippets.

@garaemon
Created May 7, 2012 06:35
Show Gist options
  • Save garaemon/2626270 to your computer and use it in GitHub Desktop.
Save garaemon/2626270 to your computer and use it in GitHub Desktop.
make a simple json from yelp neighborhood's list (http://www.yelp.com/developers/documentation/neighborhood_list)
$(function() {
$("ul.attr-list").each(function(i) {
var attr_list = $(this);
var json = {};
//var contries = $(this).children("li");
var prev_country_name = null;
$(this).children().each(function(i) {
if ($(this).get(0).tagName == "LI") {
json[$(this).html()] = {};
prev_country_name = $(this).html();
}
else if ($(this).get(0).tagName == "UL") {
//json[prev_country_name][]
var prev_region_name = null;
$(this).children().each(function(i) {
if ($(this).get(0).tagName == "LI") {
prev_region_name = $(this).html();
json[prev_country_name][prev_region_name] = [];
}
else if ($(this).get(0).tagName == "UL") {
$(this).children().each(function(i) {
if (prev_region_name != "New York, NY") {
if ($(this).get(0).tagName == "LI") {
json[prev_country_name][prev_region_name].push($(this).html());
}
}
else {
if ($(this).get(0).tagName == "LI") {
json[prev_country_name][prev_region_name].push($(this).html());
}
else if ($(this).get(0).tagName == "UL") {
$(this).children().each(function(i) {
if ($(this).get(0).tagName == "LI") {
json[prev_country_name][prev_region_name].push($(this).html());
}
});
}
}
});
//json[prev_country_name][prev_region_name].push($(this).html());
}
});
}
});
//console.log(JSON.stringify(json));
var str = JSON.stringify(json, undefined, 2);
console.log(str);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment