How to parse inner array in JSON response with PHP?

How can I get a document in a collection from MongoDB in JSON format, not in array model using PHP?

  • i am new to mongo and php. when i try retrieving document from mongo collection i get in array format. but i need to get it in json format ready. My php page where i am using the mongo act as a responder for a ajax call from javascript. so i just need to get the document and pass to the javascript. is it possible or any way to achieve this other than using json_encode.

  • Answer:

    is it possible or any way to achieve this other than using json_encode. No. The driver take BSON (not JSON) from the server and converts it into PHP hash tables (array). Basically all of the drivers do some form of BSON to Object conversion. There is no "switch" in the driver to change this behaviour. You will have to use json_encode.

Gaëtan Voyer-Perrault at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.