I have to write a javascript/jquery piece of code to display a general JSON into an html view. Basically, I get an unknown json, I parse it, and I have to build html elements reflecting the the JSON structure. Of course it is my choice to associate an html element to a peculiar JSON structure. For example, if I get the following:
[
{
"audi": {
"type": "a4",
"year": "1999",
"color": "red",
"price": "3500"
}
},
{
"fiat": {
"type": "idea",
"year": "2009",
"color": "silver",
"price": "4500"
}
}
]
I'd like to have a div containing two divs containing 4 spans each, with the type, year, color and price of the car. How can I achieve that?
EDIT:
If you want to follow an approach decoupled form any peculiar implementation you'll have to follow the suggestion of the chosen answer, however it is worth to mention this plugin (json2html) which seems to be very promising.