How to get the size of JSON object
1
In this tutorial, we will learn how to get the size of the JSON object.
Suppose this is the JSON:
var myObject = {'name':'Alax', 'address':'New York','age': '26'}
Then get the length of above JSON by the following code:
var user = {'name':'Alax', 'address':'New York','age': '26'}
var count = Object.keys(user).length;
console.log(count);
Get the length of inner JSON Object inside the main JSON
Suppose following is the JSON from which you need the length of inner JSON friends:
var user = {'
name':'Alax',
'address':'New York',
'age': '26'.
'friends':{
'friend_1': 'Jenny',
'friend_2': 'Marco',
'friend_3': 'Lucifer',
}
}
You can get the length of inner JSON friends by the following codes:
var user = {'
name':'Alax',
'address':'New York',
'age': '26'.
'friends':{
'friend_1': 'Jenny',
'friend_2': 'Marco',
'friend_3': 'Lucifer',
}
}
var count = Object.keys(user.friends).length;
console.log(count);