I insert json data to mySql database like this:
JavaScript
x
{
"socialnetwork": {
"twitter": "tw-u"
},
"information": {
"country": "Cuba",
"state": "Sancti Spiritus"
},
"settings": {
"social-enable": "1"
}
}
Now, I try to update social-enable
value using JSON_REPLACED
method like this:
JavaScript
$builder = $this->db->table('users');
$builder->where('id', 2)->set('information', "JSON_REPLACE(information, '$.settings.social-enable', '0')", false) ;
$builder->update();
In action I see this error:
JavaScript
Invalid JSON path expression. The error is around character position 27.
How do can I fix this problem?
Advertisement
Answer
… Names of keys must be double-quoted strings or valid ECMAScript identifiers (see Identifier Names and Identifiers, in the ECMAScript Language Specification). …
Try:
JavaScript
JSON_REPLACE(information, '$.settings."social-enable"', '0')
UPDATE
Try:
JavaScript
$builder->where('id', 2)->set('information', "JSON_REPLACE(information, '$.settings."social-enable"', '0')", false);