Adamhumbug Posted March 20 Share Posted March 20 Hi All, I have a function: function createContentBlock($pdo, $contentBlockType, $textBlockTitle, $textBlockContent) { $portalId = $_GET['portalId']; $json = array( "Name" => $textBlockTitle, "Content" => $textBlockContent ); $sql = "UPDATE portal_content set portal_content_json = JSON_SET( portal_content_json,'$.\"Portal Content\".\"Pages\".\"Home\".\"Content Block\"', :json) WHERE portal_attachment_id = :portalId"; $stmt = $pdo->prepare($sql); $stmt->execute([ ':portalId' => $portalId, ':json' => json_encode($json, JSON_UNESCAPED_SLASHES) ]); return "Content Block Created"; } When the data is going into the json, it looks like this: "Content Block": "{\"Name\":\"asa\",\"Content\":\"<p>asa</p>\"}" }, You will see that it is also getting an additional closing bracket. I dont know why it is going in like this as i have another function that is putting data in in the same way without this issue. Quote Link to comment https://forums.phpfreaks.com/topic/319183-saving-into-json-slashing-the-content/ Share on other sites More sharing options...
requinix Posted March 20 Share Posted March 20 Your command will set the "Content Block" value to a string which happens to contain JSON data. If you want that string value to be interpreted into a JSON value then try CAST-ing it. Quote Link to comment https://forums.phpfreaks.com/topic/319183-saving-into-json-slashing-the-content/#findComment-1618435 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.