Below is the code I use to build an HTML table on the fly (using JSON data received from the server).
I display an animated pleasewait (.gif) graphic while the data
I've been using JTemplates to accomplish what you are describing. Dave Ward has an example on his blog here. The main benefit of JTemplates is that your html isn't woven into your javascript. You write a template and call two functions to have jTemplate build the html from your template and your json.