0

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.

5
  • 1
    the inner is the array of children Commented Mar 26, 2015 at 9:40
  • 4
    "'m looking for a function" - Have you tried writing a function? Commented Mar 26, 2015 at 9:46
  • 1
    @FrancescoE. I knew that. What I meant was what it was doing in option OP now clarified it through his edit Commented Mar 26, 2015 at 9:49
  • @nnnnnn yes, of course I could write it, comment it, and maintain it - but it looks like a common enough task that there might be something I can reuse. If I don't get an answer, I'll write it and post it here. Commented Mar 26, 2015 at 9:52
  • @nnnnnn json2html.com is just what I was looking for - so now there is less code in the world to maintain ;-) Commented Mar 26, 2015 at 10:21

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.