How to have multiple JSON data in a single parameter?

I want to encode JSON data with php but failed. i have a property which is having number of parameters but i do not know how to do it. I tried severally but failed.
Am new to JSON.
I want to put parameters in general_params property as shown below but failed.
i tried this

$message='Payment made';
$general_params='{"name": "Ali Mercy","amount": "10000","txrefid": "1234567"}';
function response($validated,$message,$general_params){
    $response['validated'] = $validated;
    $response['message'] = $message;
    $response['general_params'] = $general_params;
    $json_response = json_encode($response);
    echo $json_response;

I want the output to be like this below but all failed

"validated": true,
"message":"Payment made",
"general_params": {"name": "Ali Mercy","amount": "10000","txrefid": "1234567"}

>Solution :

$general_params should be an array, not a string.

$general_params = ["name" => "Ali Mercy", "amount" => "10000", "txrefid" => "1234567"];

If you’ve been given it as a string, you can use json_decode() to parse it.

$general_params=json_decode('{"name": "Ali Mercy","amount": "10000","txrefid": "1234567"}');

Leave a Reply