How can I get data & keys from dynamic JSON file and display in table format as HTML
PS: This JSON will be dynamic and data may not be the same all the
time.
Eg: Some times, it will 2 sets or 3 sets of data, keys and values will
be different etc…
I am trying to get the JSON from https://amp.gmail.dev/playground/public/ssr_amp_list file
Results should be in below format (
key
–value
):
<div class="mySet">
<span class="myKey">id<span> - <span class="myValue">1<span>
<span class="myKey">img</span> - <span class="myValue">https://amp.dev/static/samples/img/product1_640x426.jpg</span>
<span class="myKey">name</span> - <span class="myValue">Apple</span>
<span class="myKey">price</span> - <span class="myValue">1.99</span>
<span class="myKey">stars</span> - <span class="myValue">★★</span>
<span class="myKey">attribution<span> - <span class="myValue">visualhunt</span>
<span class="myKey">url</span> - <span class="myValue">#</span>
<span class="myKey">color</span> - <span class="myValue">green</span>
<div>
<div class="mySet">
<span class="myKey">id</span> - <span class="myValue">1</span>
<span class="myKey">img</span> - <span class="myValue">https://amp.dev/static/samples/img/product1_640x426.jpg</span>
<span class="myKey">name</span> - <span class="myValue">Apple</span>
<span class="myKey">price</span> - <span class="myValue">1.99</span>
<span class="myKey">stars</span> - <span class="myValue">★★</span>
<span class="myKey">attribution</span> - <span class="myValue">visualhunt</span>
<span class="myKey">url</span> - <span class="myValue">#</span>
<span class="myKey">color</span> - <span class="myValue">green</span>
<div>
etc...
2
Answers
Below trick has done for this
jsFiddle
You can use
foreach
to display all keys and values like this: