I'm looking for a very basic example of using Javascript to parse a JSON file and output an html file or populate an html file. All the examples I've located so far have code snippets and I don't have the background to fill in the blanks between.
Thank you for any fiddles (which would be awesome), links, and smart a*s comments.
Best Answer
You can use a microtemplating library, like Mustache, to parse incoming JSON objects into HTML snippets using
{{ key }}
template syntax. If your object looks like:Using Mustache, you can render it into HTML easily using {{#}} and {{/}} to traverse nested objects:
which outputs:
Hello, my name is Joe Smith and I am 25 years old. I have red hair and blue eyes.
EDIT: more germane application - dynamically generate a control panel using a template with nested lists of objects. Here's my template and object (HTML broken into a list and joined for clarity):
Then you render with Mustache:
which outputs: