Home:ALL Converter>Update mysql json query with python

Update mysql json query with python

Ask Time:2017-09-22T12:09:41         Author:daniel

Json Formatter

I have a json field suppose from table T1 and field F1 {"X":[{"a":"1","t":"2"},{"a":"2","t":"4"}]} If i want to update my t=2 to t=10 for a:1, how to do this? What will be the normal mysql syntax?

i tried something like this it just update t=10 value separately

UPDATE T1 set F1 = JSON_SET(F1, '{"a":"1","$.t", "10"}') where id = 1; 

tried with this..it just add another value to the same field like

{"X":[{"a":"1","t":"2"},{"a":"2","t":"4"}],"t":"10"}

Thanks in advance..

Author:daniel,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/46356718/update-mysql-json-query-with-python
yy