HTML to JSON Online Converter v.1.0

This utility has been moved out of BETA and is more efficient than previously, requiring less JSON code. Unfortunately, the buildDOM function below has been changed and will not work with JSON created by the beta version of this utility.

This converter will correctly convert HTML to JSON. It is not designed to convert XML to JSON.

Though this tool can convert a whole HTML document, it is not really intended for this, rather, it's for converting HTML structures with data like a table or an unordered list (HTML tag "UL").

HTML to Convert
Trim the whitespace contained within these tags (to make the JSON more compact):
Minified JSON Output
Pretty JSON Output
HTML Output

This code will build the HTML/DOM elements from the created JSON code.

 // build DOM elements from JSON
function buildDOM1(element, obj, useCreateTextNode) {
	if (typeof obj == "string") {
		if(useCreateTextNode) {
			element.appendChild(document.createTextNode(obj));
		}
		else {
			element.innerHTML += obj;
		}
		
	}
	else if (Array.isArray(obj)) {
		for (var i = 0; i < obj.length; i++) {
			buildDOM1(element, obj[i], useCreateTextNode);
		}
	}
	else {
		var e = document.createElement(obj.tag);
		for (var prop in obj) {
			if (prop != "tag") {
				if (prop == "children") {
					buildDOM1(e, obj[prop], useCreateTextNode);
				}
				else {
					e.setAttribute(prop, obj[prop]);
				}
			}
		}
		element.appendChild(e);
	}
}
if (!Array.isArray) {
	Array.isArray = function (arg) {
		return Object.prototype.toString.call(arg) == "[object Array]";
	};
}