Encode JSON data into another JSON object
- by jburns20
I have a JSON string that I would like to include as a value in a larger JSON object that I am creating from an array. How can I create the larger JSON object without php escaping the string, and without having to decode the previously encoded string?
For example, if my JSON string is:
$encoded_already = '{"encoded_key": "encoded_value"}';
And I would like to include it in my array and json_encode() it:
$new_array = array(
"some_other_key" => $some_value,
"premade_data" => $encoded_already
);
$output = json_encode($new_array);
but I want to have the $encoded_already string be included as actual JSON, not just an escaped string.