Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ilex01's avatar

Looking for assistance in retrieving data from a two-dimensional JSON array.

$.get("https://website.com/uploads/json.json", function(data) {
	var population = JSON.stringify(data);
});
{
  "roles": [
    {"name": "admin", "id": 1}, // 1
    {"name": "sales", "id": 2} // 2
  ]
}

How do I get ['roles']['name'] 1 How do I get ['roles']['name'] 2

I try to explain what I want with the strange code above.

0 likes
2 replies
naden's avatar
  1. you need to use JSON.parse not JSON.stringify
  2. use population.roles[0].name to access the name property of the first entry
1 like
aniruddhpurohit's avatar

If you are passing JSON.stringify(data) from blade file, on Controller you should use $requestData = json_decode($request->roles);

Please or to participate in this conversation.