C
C
codercat2015-01-01 20:01:40
MySQL
codercat, 2015-01-01 20:01:40

How to update 1 specific value in json field mysql 5.7?

Mysql 5.7 added support for json fields, there are a lot of functions to work with, but I can't find how to update something in the json itself without overwriting the entire field.
For example, there is a value with this json:

{
  "key1" : "value1",
  "key2": {
    "key1": "valu1"
  }
}

What will the request to update key1 and key2.key1 look like? If this is possible, of course.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2015-01-01
@codercat

JSON_REPLACE (`json_value`, '$.key1', 'newValue1', '$.key2.key1', 'newValue2')

C
codercat, 2015-01-01
@codercat

So far, I see only one solution - get the record, replace the value with a new one, and completely overwrite it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question