intermediatejson MySQL MariaDB SQL Server PostgreSQL SQLite
Update a Value Inside a JSON Column
Modify a single key in a stored JSON document without replacing the whole object, using `JSON_SET` (MySQL/MariaDB/SQLite), `JSON_MODIFY` (SQL Server), or `jsonb_set` (PostgreSQL).
Created Last updated 5/5 supported engines validation-green1 example2 scenarios
Docker-validated Not currently validation-green
Example 1
Change the theme value inside a JSON settings column
The UPDATE rewrites only the theme key while leaving lang untouched — the stored document becomes {"theme": "dark", "lang": "en"}. In MySQL and MariaDB, JSON_UNQUOTE(JSON_EXTRACT(...)) strips the surrounding quotes from the JSON string value; using the ->> shorthand (config->>'$.theme') is equivalent. In PostgreSQL, config->>'theme' extracts the text value of the key directly (without JSON-literal quotes). The jsonb_set path '{theme}' is a PostgreSQL text array; for a nested key like user.theme use '{user,theme}'. In SQL Server, JSON_MODIFY is also used for arrays: JSON_MODIFY(config, '$.tags[0]', 'urgent') updates the first element. To add a key that does not yet exist, JSON_SET and JSON_MODIFY both insert it automatically; to remove a key, use JSON_REMOVE(config, '$.theme') in MySQL/MariaDB/SQLite or JSON_MODIFY(config, '$.theme', NULL) in SQL Server.
UPDATE settings
SET
config = JSON_SET (config, '$.theme', 'dark')
WHERE
id = 1;
SELECTJSON_UNQUOTE (JSON_EXTRACT (config, '$.theme')) AS theme
FROM
settings
WHERE
id = 1;
UPDATE settings
SET
config = JSON_MODIFY (config, '$.theme', 'dark')
WHERE
id = 1;
SELECTJSON_VALUE (config, '$.theme') AS theme
FROM
settings
WHERE
id = 1;
UPDATE settings
SET
config = json_set (config, '$.theme', 'dark')
WHERE
id = 1;
SELECTjson_extract (config, '$.theme') AS theme
FROM
settings
WHERE
id = 1;
Expected result
theme
dark
All supported engines return the same result; only the update and extraction syntax differs.
Useful when
Where this command helps.
updating a user's preferred theme stored inside a JSONB settings column without overwriting other preferences
patching a single field in a product metadata JSON column from an automated background job
Explanation
What the command is doing.
When a table stores configuration, metadata, or user preferences in a JSON column, it is often necessary to update a single key without reading the document into application code, modifying it, and writing it back. All major engines provide a function that performs an in-place key update and returns the modified document. MySQL, MariaDB, and SQLite use JSON_SET(column, '$.key', value), which sets the key if it exists and inserts it if it does not. SQL Server uses JSON_MODIFY(column, '$.key', value) with the same semantics. PostgreSQL uses jsonb_set(column, '{key}', 'json_value'::jsonb), where the path is an array literal and the new value must itself be valid JSON — string values must include the quotes, e.g. '"dark"'. To delete a key, pass NULL as the value (MySQL/SQLite/SQL Server) or use the - operator (PostgreSQL: column - 'key'). Nested paths are supported on all engines using dot or array notation: '$.user.theme' or '{user,theme}' in PostgreSQL.