0

I insert json data to mySql database like this:

{
    "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:

$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:

Invalid JSON path expression. The error is around character position 27.

How do can I fix this problem?

1 Answer 1

1

JSON Path Syntax

... Names of keys must be double-quoted strings or valid ECMAScript identifiers (see Identifier Names and Identifiers, in the ECMAScript Language Specification). ...

Try:

... JSON_REPLACE(information, '$.settings."social-enable"', '0') ...

UPDATE

Try:

$builder->where('id', 2)->set('information', "JSON_REPLACE(information, '$.settings.\"social-enable\"', '0')", false);
Sign up to request clarification or add additional context in comments.

1 Comment

Right, I add "social-enable" in my query like your solution but I see new syntax this error in my code: syntax error, unexpected 'social' (T_STRING), expecting ')'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.