php - How to properly format data as JSON -


i working on hotels api, needs send data in json form,

but json form wrong , api not working.

my code is:-

$json = json_encode([     'roomguests' => [ json_encode(["noofadults"=> 1,"noofchild"=> 0,"childage"=> null])], ]); 

and output :-

{ "roomguests": [ "{\"noofadults\":1,\"noofchild\":0,\"childage\":null}"  ] } 

and want result this:-

{ "roomguests": [{     "noofadults": 1,     "noofchild": 0,     "childage": null }],  } 

please let me know how solve issue.

use

$json = json_encode([     'roomguests' => [["noofadults"=> 1,"noofchild"=> 0,"childage"=> null]], ]);  echo $json; 

this results

{     "roomguests": [         {             "noofadults": 1,             "noofchild": 0,             "childage": null         }     ] }