 <p>For a working doodle/proof of concept of an approach to utilize pure JavaScript along with the familiar and declarative pattern behind XSLT's matching expressions and recursive templates, see <a href="https://gist.github.com/brettz9/0e661b3093764f496e36" rel="nofollow">https://gist.github.com/brettz9/0e661b3093764f496e36</a></p> <p>(A similar approach might be taken for JSON.)</p> <p>Note that the demo also relies on JavaScript 1.8 expression closures for convenience in expressing templates in Firefox (at least until the ES6 short form for methods may be implemented).</p> <p>Disclaimer: This is my own code.</p>