Hemant singh
Hemant singh

Reputation: 35

How to Update a JSON Column in MySQL

Example the data column has

{"default_account":188,"default_bu-207":948}

update user_preference 
    set data = JSON_REMOVE(data,'$.default_bu-207')
where JSON_EXTRACT(data,'$.default_bu-207') = 948

for this query i am getting error

Invalid JSON path expression.

The error is around character position 16.*

tried escaping - but it is throwing same error

Upvotes: 0

Views: 50

Answers (1)

Bill Karwin
Bill Karwin

Reputation: 562871

https://dev.mysql.com/doc/refman/8.0/en/json.html says:

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).

Since your key name contains a punctuation character, you must use double quotes:

... JSON_REMOVE(data,'$."default_bu-207"') ...

Upvotes: 2

Related Questions