I have an JSON object of posts:
{
"how-to-create-a-blog": {
"post-url": "blog/how-to-create-a-blog.html",
"post-image": "/posts/post-image.jpg",
"post-title": "How to create a blog"
},
"how-to-create-a-mega-menu": {
"post-url": "blog/how-to-create-a-mega-menu.html",
"post-image": "/posts/post-image.jpg",
"post-title": "How to create a mega menu"
},
"what-is-wordpress": {
"post-url": "blog/what-is-wordpress.html",
"post-image": "/posts/post-image.jpg",
"post-title": "What is WordPress"
},
"create-your-first-wordpress-theme": {
"post-url": "blog/create-your-first-wordpress-theme.html",
"post-image": "/posts/post-image.jpg",
"post-title": "Create your first wordpress theme"
}
}
the JSON object structure is:
{
"post-id": {
"post-url": "",
"post-image": "",
"post-title": ""
}
}
I need to count number of post with jQuery length but it gives undefined error.
$.getJSON('/all-posts.json', function(data) {
var postNumbers = data[0];
console.log(postNumbers.length);
});