Если вы хотите извлечь данные из файла JSON, вы можете использовать для этого 'jQuery .get JSON ()'. Вы можете просто написать этот вызов как:
$.getJSON('result.json', function(data) {
//here data is your retrived json obj, do further processing with it like i have done below
});
Лучше получить данные из внешнего JSON файла, в противном случае вы можете сделать это следующим образом:
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<script>
$(document).ready(function() {
var products = [{
"id": "1",
"name": "Book Name 1",
"category": "Computers",
"price": "$ 123",
"image": "https://static.boredpanda.com/blog/wp-content/uuuploads/tunnel-of-love-ukraine/tunnel-of-love-ukraine-6.jpg"
},
{
"id": "1",
"name": "Book Name 1",
"category": "Computers",
"price": "$ 123",
"image": "https://static.boredpanda.com/blog/wp-content/uuuploads/tunnel-of-love-ukraine/tunnel-of-love-ukraine-6.jpg"
},
{
"id": "1",
"name": "Book Name 1",
"category": "Computers",
"price": "$ 123",
"image": "https://static.boredpanda.com/blog/wp-content/uuuploads/tunnel-of-love-ukraine/tunnel-of-love-ukraine-6.jpg"
},
{
"id": "1",
"name": "Book Name 1",
"category": "Computers",
"price": "$ 123",
"image": "https://static.boredpanda.com/blog/wp-content/uuuploads/tunnel-of-love-ukraine/tunnel-of-love-ukraine-6.jpg"
},
{
"id": "1",
"name": "Book Name 1",
"category": "Computers",
"price": "$ 123",
"image": "https://static.boredpanda.com/blog/wp-content/uuuploads/tunnel-of-love-ukraine/tunnel-of-love-ukraine-6.jpg"
},
{
"id": "1",
"name": "Book Name 1",
"category": "Computers",
"price": "$ 123",
"image": "https://static.boredpanda.com/blog/wp-content/uuuploads/tunnel-of-love-ukraine/tunnel-of-love-ukraine-6.jpg"
},
{
"id": "1",
"name": "Book Name 1",
"category": "Computers",
"price": "$ 123",
"image": "https://static.boredpanda.com/blog/wp-content/uuuploads/tunnel-of-love-ukraine/tunnel-of-love-ukraine-6.jpg"
},
{
"id": "1",
"name": "Book Name 1",
"category": "Computers",
"price": "$ 123",
"image": "https://static.boredpanda.com/blog/wp-content/uuuploads/tunnel-of-love-ukraine/tunnel-of-love-ukraine-6.jpg"
},
{
"id": "1",
"name": "Book Name 1",
"category": "Computers",
"price": "$ 123",
"image": "https://static.boredpanda.com/blog/wp-content/uuuploads/tunnel-of-love-ukraine/tunnel-of-love-ukraine-6.jpg"
},
{
"id": "2",
"name": "Book Name 2",
"category": ["Science", "Programming"],
"price": "$ 319",
"image": "https://static.boredpanda.com/blog/wp-content/uuuploads/tunnel-of-love-ukraine/tunnel-of-love-ukraine-6.jpg"
},
{
"id": "2",
"name": "Book Name 2",
"category": ["Science", "Programming"],
"price": "$ 319",
"image": "https://static.boredpanda.com/blog/wp-content/uuuploads/tunnel-of-love-ukraine/tunnel-of-love-ukraine-6.jpg"
},
{
"id": "2",
"name": "Book Name 2",
"category": ["Science", "Programming"],
"price": "$ 319",
"image": "https://static.boredpanda.com/blog/wp-content/uuuploads/tunnel-of-love-ukraine/tunnel-of-love-ukraine-6.jpg"
}
];
var j = 0;
var content = "";
for (var i in products) {
if (i % 6 === 0) {
$("#products").append("<tr id='row" + i + "'></tr>");
j = i;
}
$("#row" + j).append("<td><div><img src='" + products[i].image + "' style='width:130px;height:200px;'></div><div class='text-center'>" + products[i].name + " </br><div>" + products[i].price + "</div></div></td>");
}
});
</script>
</head>
<body>
<table class="table">
<tbody id="products"></tbody>
</table>
</body>
</html>
Здесь вам не нужно добавлять строки вручную, просто добавьте больше данных в ваш JSON объект, и строка будет добавлена автоматически
У меня нет здесь добавлены любые стили CSS, поэтому добавляйте в соответствии с вашими потребностями, надеюсь, это поможет.