1+----+--------+-------+-------+---------------------------------+
2| id | name | price | stock | attr |
3+----+--------+-------+-------+---------------------------------+
4| 2 | Shirt | 10.50 | 78 | {"size": 42, "colour": "white"} |
5| 3 | Blouse | 17.00 | 15 | {"colour": "white"} |
6+----+--------+-------+-------+---------------------------------+
7
8SELECT name FROM clothes WHERE JSON_EXTRACT(attr, '$.size') = 42;
1+----+--------+-------+-------+---------------------------------+
2| id | name | price | stock | attr |
3+----+--------+-------+-------+---------------------------------+
4| 2 | Shirt | 10.50 | 78 | {"size": 42, "colour": "white"} |
5| 3 | Blouse | 17.00 | 15 | {"colour": "white"} |
6+----+--------+-------+-------+---------------------------------+
7
8UPDATE
9 Clothes
10SET
11 attr = JSON_REMOVE(attr, '$.size');
12WHERE
13 id = 2;
14
15+----+--------+-------+-------+---------------------------------+
16| id | name | price | stock | attr |
17+----+--------+-------+-------+---------------------------------+
18| 2 | Shirt | 10.50 | 78 | {"colour": "white"} |
19| 3 | Blouse | 17.00 | 15 | {"colour": "white"} |
20+----+--------+-------+-------+---------------------------------+
1+----+--------+-------+-------+---------------------------------+
2| id | name | price | stock | attr |
3+----+--------+-------+-------+---------------------------------+
4| 2 | Shirt | 10.50 | 78 | {"size": 42, "colour": "white"} |
5| 3 | Blouse | 17.00 | 15 | {"colour": "white"} |
6+----+--------+-------+-------+---------------------------------+
7
8UPDATE
9 Clothes
10SET
11 attr = JSON_INSERT(attr, '$.size', 40);
12WHERE
13 id = 3;
14
15+----+--------+-------+-------+---------------------------------+
16| id | name | price | stock | attr |
17+----+--------+-------+-------+---------------------------------+
18| 2 | Shirt | 10.50 | 78 | {"size": 42, "colour": "white"} |
19| 3 | Blouse | 17.00 | 15 | {"colour": "white", "size": 40} |
20+----+--------+-------+-------+---------------------------------+