当作为JSON返回时,如何保持数组结构不变?

I have a problem, I have a multidimensional array of some data that I am returning as JSON through an API, I want the data as a JSON array, the array is structured properly in PHP but when I return it through API as JSON it becomes a JSON object of objects, I want the data in same structure as I kept in PHP while producing the array. I have tried casting the object as array, array is perfect in PHP but IN JSON it becomes object of objects. How could i return JSON data as array.

{
   "standards":{
      "standard_1":{
         "subjects":{
            "English":{
               "topics":[

               ]
            },
            "Physics":{
               "topics":{
                  "topic":[
                     {
                        "id":"2",
                        "standard_id":"1",
                        "subject_id":"3",
                        "topic":"topic",
                        "title":"dgfdgfdg",
                        "option_1":"dfgdfggdgfdg",
                        "option_2":"dfgfd",
                        "option_3":"gdfgfdg",
                        "option_4":"dfgdfgdg",
                        "correct_answer":"option_2"
                     }
                  ],
                  "test topic":[
                     {
                        "id":"6",
                        "standard_id":"1",
                        "subject_id":"3",
                        "topic":"test topic",
                        "title":"title",
                        "option_1":"1",
                        "option_2":"2",
                        "option_3":"3",
                        "option_4":"4",
                        "correct_answer":"option_2"
                     }
                  ]
               }
            },
            "sports":{
               "topics":[

               ]
            },
            "Maths":{
               "topics":{
                  "topic":[
                     {
                        "id":"1",
                        "standard_id":"1",
                        "subject_id":"21",
                        "topic":"topic",
                        "title":"This is a updated test question",
                        "option_1":"1",
                        "option_2":"2",
                        "option_3":"3",
                        "option_4":"4",
                        "correct_answer":"option_2"
                     }
                  ]
               }
            },
            "test subject":{
               "topics":[

               ]
            }
         }
      },
      "standard_2":{
         "subjects":{
            "Math":{
               "topics":[

               ]
            },
            "Chemistry":{
               "topics":{
                  "topic":[
                     {
                        "id":"4",
                        "standard_id":"2",
                        "subject_id":"4",
                        "topic":"topic",
                        "title":"sfsfsfs",
                        "option_1":"fdsfs",
                        "option_2":"fsfs",
                        "option_3":"fsdfsdf",
                        "option_4":"sdfdsfds",
                        "correct_answer":"option_1"
                     }
                  ]
               }
            },
            "test sub":{
               "topics":{
                  "fghgfh":[
                     {
                        "id":"3",
                        "standard_id":"2",
                        "subject_id":"19",
                        "topic":"fghgfh",
                        "title":"Title",
                        "option_1":"fhfhf",
                        "option_2":"hfhf",
                        "option_3":"hgfhf",
                        "option_4":"fhfghfhfh",
                        "correct_answer":"option_4"
                     }
                  ]
               }
            }
         }
      },
      "standard_3":{
         "subjects":{
            "Sports":{
               "topics":[

               ]
            }
         }
      },
      "standard_4":{
         "subjects":{
            "new subject":{
               "topics":[

               ]
            },
            "Computer":{
               "topics":{
                  "Basics":[
                     {
                        "id":"7",
                        "standard_id":"4",
                        "subject_id":"24",
                        "topic":"Basics",
                        "title":"What is a computer",
                        "option_1":"Machine",
                        "option_2":"Aeroplane",
                        "option_3":"Device",
                        "option_4":"Robot",
                        "correct_answer":"option_1"
                     }
                  ]
               }
            }
         }
      },
      "standard_5":{
         "subjects":{
            "Math":{
               "topics":[

               ]
            },
            "":{
               "topics":[

               ]
            },
            "History":{
               "topics":[

               ]
            }
         }
      },
      "standard_6":{
         "subjects":[

         ]
      },
      "standard_7":{
         "subjects":{
            "Sports":{
               "topics":[

               ]
            },
            "Civics":{
               "topics":[

               ]
            }
         }
      },
      "standard_8":{
         "subjects":[

         ]
      },
      "standard_9":{
         "subjects":[

         ]
      },
      "standard_10":{
         "subjects":{
            "History":{
               "topics":[

               ]
            },
            "Math":{
               "topics":[

               ]
            }
         }
      },
      "standard_11":{
         "subjects":[

         ]
      },
      "standard_12":{
         "subjects":[

         ]
      }
   }
}

[standard_1] => Array
            (
                [subjects] => Array
                    (
                        [English] => Array
                            (
                                [topics] => Array
                                    (
                                    )

                            )

                        [Physics] => Array
                            (
                                [topics] => Array
                                    (
                                        [topic] => Array
                                            (
                                                [0] => stdClass Object
                                                    (
                                                        [id] => 2
                                                        [standard_id] => 1
                                                        [subject_id] => 3
                                                        [topic] => topic
                                                        [title] => dgfdgfdg
                                                        [option_1] => dfgdfggdgfdg
                                                        [option_2] => dfgfd
                                                        [option_3] => gdfgfdg
                                                        [option_4] => dfgdfgdg
                                                        [correct_answer] => option_2
                                                    )

                                            )

                                        [test topic] => Array
                                            (
                                                [0] => stdClass Object
                                                    (
                                                        [id] => 6
                                                        [standard_id] => 1
                                                        [subject_id] => 3
                                                        [topic] => test topic
                                                        [title] => title
                                                        [option_1] => 1
                                                        [option_2] => 2
                                                        [option_3] => 3
                                                        [option_4] => 4
                                                        [correct_answer] => option_2
                                                    )

                                            )

                                    )

                            )

                        [sports] => Array
                            (
                                [topics] => Array
                                    (
                                    )

                            )

                        [Maths] => Array
                            (
                                [topics] => Array
                                    (
                                        [topic] => Array
                                            (
                                                [0] => stdClass Object
                                                    (
                                                        [id] => 1
                                                        [standard_id] => 1
                                                        [subject_id] => 21
                                                        [topic] => topic
                                                        [title] => This is a updated test question
                                                        [option_1] => 1
                                                        [option_2] => 2
                                                        [option_3] => 3
                                                        [option_4] => 4
                                                        [correct_answer] => option_2
                                                    )

                                            )

                                    )

                            )

                        [test subject] => Array
                            (
                                [topics] => Array
                                    (
                                    )

                            )

                    )

            )

Any idea?

What you're looking for is probably json_decode($jsonString,true); . It will convert the objects inside the json into arrays

if you want your json object to be returned as array in php just use json_decode($json,true); more info

if you want to be sure that your php array is correctly converted to json use json_encode($phpArray,JSON_FORCE_OBJECT) more info