How to read and get the count from rest api JSON response?

Hi,
I have a json array response like below:

[
	{
		name : john
		dept: Mech
		Rank : A
	}
	{
		name : Mecury
		dept: Science
		Rank : A+
	}
	{
		name : Sana
		dept: Bio
		Rank : B
	}
]

when i try to get the length of the array i couldnt able to do that, because i dont have any prefix on the response i guess.

Is there any way i can get the length from this json array?

A repro in the playground would be nice. It is not directly related to babylon but in general you could do response.length ?

not its throwing an wrong data when i tested on this below code:

var xhr = new XMLHttpRequest();
    xhr.open("GET", "https://jsonplaceholder.typicode.com/posts", true);
    xhr.onload = function(){
        console.log(xhr.responseText);
        console.log(xhr.responseText.length);

    };
    xhr.send(); 

You need to parse the text response in this case with JSON.parse

var jparse = JSON.parse(responsetext);
    var leng = Object.keys(jparse).length;
    console.log(leng);
   

tried this code but getting a syntax error:
image

This works: Babylon.js Playground

Please, focus your topics around Babylon next time :slight_smile:

Thank you :slight_smile:

Getting ah 400 Bad Request error when i try to send the json data to below formate:

[
  {
    "postId": 1,
    "id": 1,
    "name": "id labore ex et quam laborum",
    "email": "Eliseo@gardner.biz",
    "body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"
  },
  {
    "postId": 1,
    "id": 2,
    "name": "quo vero reiciendis velit similique earum",
    "email": "Jayne_Kuhic@sydney.com",
    "body": "est natus enim nihil est dolore omnis voluptatem numquam\net omnis occaecati quod ullam at\nvoluptatem error expedita pariatur\nnihil sint nostrum voluptatem reiciendis et"
  },
  {
    "postId": 1,
    "id": 3,
    "name": "odio adipisci rerum aut animi",
    "email": "Nikita@garfield.biz",
    "body": "quia molestiae reprehenderit quasi aspernatur\naut expedita occaecati aliquam eveniet laudantium\nomnis quibusdam delectus saepe quia accusamus maiores nam est\ncum et ducimus et vero voluptates excepturi deleniti ratione"
  },
  {
    "postId": 1,
    "id": 4,
    "name": "alias odio sit",
    "email": "Lew@alysha.tv",
    "body": "non et atque\noccaecati deserunt quas accusantium unde odit nobis qui voluptatem\nquia voluptas consequuntur itaque dolor\net qui rerum deleniti ut occaecati"
  },
  {
    "postId": 1,
    "id": 5,
    "name": "vero eaque aliquid doloribus et culpa",
    "email": "Hayden@althea.biz",
    "body": "harum non quasi et ratione\ntempore iure ex voluptates in ratione\nharum architecto fugit inventore cupiditate\nvoluptates magni quo et"
  }
]

Can you please tell me what i am missing here?

Your server is returning this so it means you are not sending the expected format, I will move the post to off topic.