How do I get the length of a JSON file?

First, you’ll have to create a properly formatted JSON file. Once you’re done with that, getting the current number of objects from that list is a piece of cake.

<script>
$.getJSON('json/myjsonfile.json',function(data){
var json = data;
alert(json.length);
});
</script>

Pull in the feed via getJSON function, toss it into a variable (I called mine json) and grab the length with .length. My example alerts the number of entries but you can do what ever you’d like.

Back to Blog

Say Hello

You can reach me by email, I'd love to hear from you.