0

I have this Json file what I want to do is access all the "name" attributes.Is there any way to access that attribute.And I want to do this with PHP (laravel). since this json got dynamic name I can't figure out a away to access this.

[
[
    {
        "2": {
            "id": 2,
            "name": "Asiri Medical Hospital - Kirula Road - Colombo 05",
            "specializations": [
                {
                    "id": 58,
                    "name": "Endocrinologist"
                },
                {
                    "id": 122,
                    "name": "Diabetologist"
                }
            ]
        },
        "3": {
            "id": 3,
            "name": "Asiri Central Hospital - Norris Canal Road-Colombo 10",
            "specializations": [
                {
                    "id": 58,
                    "name": "Endocrinologist"
                },
                {
                    "id": 122,
                    "name": "Diabetologist"
                }
            ]
        },
        "11": {
            "id": 11,
            "name": "Ninewells Care Mother and Baby Hospital (Pvt) Ltd",
            "specializations": [
                {
                    "id": 58,
                    "name": "Endocrinologist"
                }
            ]
  }
]

]

  • Question is marked as duplicate, but with WRONG question specified in duplicate. Actual duplicate is: https://stackoverflow.com/questions/40635146/laravel-pluck-fields-from-relations – Joas May 06 '18 at 14:26

1 Answers1

-1

The easy way is with file_get_contents. And then json_decode the result of file_get_contents.

$json = json_decode(file_get_contents($path_to_file))

Then you can use al different array functions to get what you want.

Leroy
  • 1,600
  • 13
  • 23