Haris Khan
Haris Khan

Reputation: 125

How to insert nested json data in mysql table?

I am trying to update my mysql table and insert json data to my mysql table's json-datatype column using JSON_INSERT. Here is the structure of my column.

{
"Data": 
     [{
      "Devce": "ios", 
      "Status": 1
      }]
}

This is the query I am using to insert more data to this field.

UPDATE table SET `Value` = JSON_INSERT
(`Value`,'$.Data','{\"Device\":\"ios\",\"Status\":1}') WHERE Meta = 'REQUEST_APP'

This is supposed to update the field to this:

{
    "Data": 
         [{
          "Devce": "ios", 
          "Status": 1
          },
    {
          "Devce": "ios", 
          "Status": 1
          }
]
    }

But instead it the result is:

0 rows affected. (Query took 0.0241 seconds.)

Any help regarding this would be appreciated.

Upvotes: 6

Views: 1990

Answers (1)

Carlos Gonzalez
Carlos Gonzalez

Reputation: 878

JSON_APPEND serves your purpose better JSON_APPEND docs

Upvotes: 2

Related Questions