CodeIgniter Forums
Json in entity have backslashes - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Json in entity have backslashes (/showthread.php?tid=83604)



Json in entity have backslashes - ozornick - 10-10-2022

I add an array to the property, which is converted to JSON.

In the original, the caster produces a good result, but when saving to an entity (not yet saved to the database), backslashes appear in output:

PHP Code:
//  is wrong string (json-array)
$entity->attributes['tables'string (29""[\"one\",\"two\",\"three\"]""

// cast after normally
$entity->tables string (21) "["one","two","three"]"

// raw casting array
json_encode(...) string (21) "
["one","two","three"]


where problem?