-1

I need to parse the below json with jquery and display in a html table.

display the values of "key" and "doc_count" in a html table.

Help is appreciated. see json below:

{ "key": "A", "count": 100 }, { "key": "AB", "count": 800 }

6
  • so what you tried for that ? Commented Nov 20, 2015 at 10:47
  • See datatables, that's what I use and it works perfectly Commented Nov 20, 2015 at 10:50
  • .aggregations.2.buckets not working? Commented Nov 20, 2015 at 10:52
  • dynatable.com Commented Nov 20, 2015 at 10:54
  • any idea how to do this with jquery? Commented Nov 20, 2015 at 11:07

1 Answer 1

1

Try This code:

Use any Template Engine(Handlebars or Underscore) to process HTML. I am assuming data is in the form of Static Json.

Make a table and append to HTML page:

var Table=$("<table class='json_data'>");
$('body').append(Table);

Then iterate whole Json to get the desired value.Like this:

$.each(parse_json.aggregations[2].buckets,function(index,value){
   $('.json_data').append("<tr><td>"+value.key+"</td><td>"+value.doc_count+"</td></tr>");
})

JSFiddle Link: https://jsfiddle.net/Dee0565/17u4xs3s/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.