SyntaxStudy
Sign Up
MySQL Modifying JSON Values
MySQL Intermediate 4 min read

Modifying JSON Values

JSON_SET and JSON_REPLACE

JSON_SET inserts or updates a path. JSON_REPLACE only updates existing paths. JSON_INSERT only inserts new paths.

Example
UPDATE products
SET attributes = JSON_SET(
  attributes,
  '$.ram', 32,
  '$.gpu', 'RTX 4090'
)
WHERE id = 1;

SELECT attributes FROM products WHERE id = 1;
Pro Tip

JSON_SET is the safe default — it does both insert and update.