Encode JSON data into another JSON object

Posted by jburns20 on Stack Overflow See other posts from Stack Overflow or by jburns20
Published on 2012-06-22T02:53:26Z Indexed on 2012/06/22 3:16 UTC
Read the original article Hit count: 348

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about php

Related posts about JSON