html - Building table from json array with Mustache.JS - how to auto row-span? -


i trying auto-generate html given json containing nested arrays in following structure:

{   "aggregations": {     "application": {       "buckets": [         {           "key": "server",           "levels": {             "buckets": [               {                 "key": "error",                 "msg": {                   "buckets": [                     { "key": "timeout ", "doc_count": 10},                     { "key": "memory ", "doc_count": 5}                   ]                 }               },               {                 "key": "warn",                 "msg": {                   "buckets": [                     { "key": "mismatch ", "doc_count": 7},                     { "key": "authentication ", "doc_count": 3}                   ]                 }               }             ]           }         },         {           "key": "backend",           "levels": {             "buckets": [               {                 "key": "info",                 "msg": {                   "buckets": [                     { "key": "success ", "doc_count": 13},                     { "key": "connected ", "doc_count": 5}                   ]                 }               },               {                 "key": "warn",                 "msg": {                   "buckets": [                     { "key": "dropped ", "doc_count": 7}                   ]                 }               }             ]           }         },         {           "key": "frontend",           "levels": {             "buckets": [               {                 "key": "fatal",                 "msg": {                   "buckets": [                     { "key": "crashed ", "doc_count": 13}                   ]                 }               },               {                 "key": "warn",                 "msg": {                   "buckets": [                     { "key": "not connected ", "doc_count": 5},                     { "key": "failed ", "doc_count": 7}                   ]                 }               }             ]           }         }       ]     }   } } 

i following table:

expected-table

here html tried writing using mustache:

<table width='400px' border='1'>     <thead>     <tr>         <th>application</th>         <th>level</th>         <th>msg</th>         <th>occurance</th>     </tr>     </thead>     <tbody>     {{#payload.aggregations.application.buckets}}     <tr>         <td>{{key}}</td>         {{#levels.buckets}}         <td>{{key}}</td>         {{#msg.buckets}}         <td >{{key}}</td>         <td >{{doc_count}}</td>         {{/msg.buckets}}{{/levels.buckets}}     </tr>     {{/payload.aggregations.application.buckets}}     </tbody> </table> 

this gives me:

enter image description here

how automatically row-span application , level columns? when try adding <tr> before each array iteration - put each word in new line


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -