I'm looking for a function which can transform:
{ tag: 'form',
inner: [
{ tag: 'input', params: { type: 'text' } },
{ tag: 'select',
inner: [
{ tag: 'option', params: { value: 0 },
inner: ['zero']
},
{ tag: 'option', params: { value: 1 },
inner: ['one']
}
]
}
]
}
into:
<form>
<input type="text"></input>
<select>
<option value="0">zero</option>
<option value="1">one</option>
</select>
</form>
I'm not looking for a templating system such as handlebars.
I'm flexible about the Javascript object's required property names, etc. - it's just an example of the JS representation of HTML that I want to be able to build up and modify, before "rendering" to HTML.
I'm not asking anyone to write code - I'd just like to know if there is an existing function that I'm not aware of.
Please don't write code for this. Especially code that uses the DOM, as this is a server-side question and I've previously had nasty issues with NodeJS's fake DOMs.
AFAIK, there is no built-in implementation of such a function. However I've found this after a quick search on Google: http://json2html.com/
Seems pretty much similar to what you'are asking for.