We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Request::getJsonRawBody() as array, not as object

Is there any way to get complete JSON object as array, sorry if this has already been

edited Aug '16

Perhaps this thread can help? https://forum.phalcon.io/discussion/4647/getjsonrawbody-objects-or-arrays

Also docs here: https://docs.phalcon.io/en/latest/api/Phalcon_Http_Request.html

edited Sep '16

Why don't you simply cast it as an array, i.e. (array) $yourJsonObject? Sure, it might be multi dimensional, so in that case you'll need to do:

/ First we convert an object to a json string, then we convert the json string to an array
$jsonArray = json_decode(json_encode($yourJsonObject), 0xff);

EDIT: actually getJsonRawBody() method does support 'associative' parameter as pointed in a link provided here by @nikolay-mihaylov

Still, I believe it's good to know when you don't have other option, json_**code native PHP does the job in both directions.

if i put TRUE inside inside Request::getJsonRawBody(true) I'll get a array as assoc