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

sos99's avatar
Level 7

missing documantion - API Resource sub Object of Objects!

Hi :)

when I use API resources it makes a sub-array of object How do I force him to make sub Object of Objects

"sub_object" - should be Object of Objects!

The final result that should be :

{
  "object": [
    {
      "username": "username",
      "lastname": "lastname",
      "sub_object": {
        "object_1": {
          "sub_object_name": "something",
          "sub_object_status": "wow",
        },
        "object_2": {
          "sub_object_name": "something2",
          "sub_object_status": "wow2",
        },
      }
    }
  ],
}

thanks!
0 likes
3 replies
rodrigo.pedra's avatar

Show some code where you are having this issue. Right now this is very vague.

tykus's avatar
tykus
Best Answer
Level 104

If the sub_object array has non-numeric or non-zero indexed keys; you will get an object. You can force this by mapping over the sub_object array.

Please or to participate in this conversation.