In my API, I use resources for all the endpoints. For the most part, I'm returning arrays of data and they work just fine. However, for a couple of endpoints, I have some data that looks something like the following:
[
"123" => ["total"=>123, "average"=>12.7],
"456" => ["other"=>"data"],
]
where the keys are the ids for other objects already provided by the API. However, when I send that data to the resource, the response essentially turns the data into a straight array, so the JSON representation looks as follows:
[
["total": 123, "average": 12.7],
["other": "data"]
]
I'm thinking this is more of an issue issue with json_encode underneath the hood, but is there anything I can do in the toArray() method to keep the keys when they're numeric strings? The only things that have worked for me so far are to prepend a non-numeric string key (e.g. dummy to the object), or to add a letter to each key (e.g. a123, a456, etc.).