Creating a UI/writing HTML from a JSON file -
i have long, unwieldy, unformatted json file generated lighthouse (a tool conducts page load time analysis- file has results of tests). in order make formatted readable people, need apparently create ui around file. problem i'm not sure how begin working on it.
i've read creating html json objects, think i'd try display information tests in browser right now... write that? have 1 node.js file right now, running tests , using json.stringify()
stick json'd results file. can generate html right after create json? (and main question- how create html json file?)
i'm starting out node , json, tips highly appreciated.
yes, can create html json file.
here's simple example done jquery, first creating array of of elements, , using .join("")
parse them. once parse, can appended anywhere in dom:
var json_file = { "one": "hi there", "two": "another item", "three": "third item" } var items = []; $.each(json_file, function(key, val) { items.push("<li id='" + key + "'>" + val + "</li>"); }); $("<ul/>", { "class": "json-list", html: items.join("") }).appendto("body"); // sample extension showcasing manipulation of inserted html $(".json-list #two").css('color', 'red');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
obviously, more complicated json (and desired html structure), more complicated method of parsing json going be.
a templating engine make job easier, , there , hunderds of these. of more popular ones are:
hope helps! :)
Comments
Post a Comment