0

I am writing java servlet using tomcat as servlet container.

I need a client to create an ajax-request and get json object as response.

After that client construct a HTMLElement from this json object (parsing it to js object first).

The question: is there a way to have a complete element right after parsing a json without manually setting attribute to attribute (like, HTMLElement.Property = Parsed_Json.Property)?

Because if I need to set all this manually, then I need to know what type of element I get (and use one field in JSON as tagName). But this will require something like

var button = document.createElement(Parsed_Json.ElementTag);

And then a big "if" block to realize which properties I need to set.

Maybe I can replicate the structure of a complete object in json so it will be usable right after

var HTMLElement = Json.parse(json_object); 

and I will be able to do just a

body.appendChild(HTMLElement);
Danetta
  • 1
  • 3
  • Possible duplicate of [Create HTML table from JavaScript object](https://stackoverflow.com/questions/17684201/create-html-table-from-javascript-object) – nikli Sep 07 '17 at 09:41
  • This [code snippet](https://stackoverflow.com/a/14197981/1502615) should help you in displaying JSON content on HTML. – Punith Mithra Sep 07 '17 at 09:41

0 Answers0