You can't use a JSON path with wildcards in a JSON_SET() function.

https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-set

... an error occurs if the json_doc argument is not a valid JSON document or any path argument is not a valid path expression or contains a * or ** wildcard.

So you can change only one value at a time with JSON_SET(). I assume you have a variable number of entries in the JSON array, it isn't always two as in your example. If you want to change all of them, you'd have to write a JSON_SET() with multiple paths.

JSON_SET(gameresults, '$.scores[1].seen', true, '$.scores[2].seen', true, ...)

Another solution would be to fetch the whole JSON document into your application, modify it however you want using client code, and then post then whole JSON document back to the database.

It would be much easier if you did not store your data in JSON format. Store them in a second table with one row per score, using normal columns, not JSON. Then you can use very simple SQL to update them:

UPDATE gamescores SET seen = true 
WHERE gameId = 'acaa2a99-a24c' AND scoreId = '14916624';

You can store data in normal rows and columns, but still format a JSON response when you want to return them to your C# application. Read about JSON_ARRAYAGG() and JSON_OBJECT() functions.

Answer from Bill Karwin on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › working-with-json-in-mysql
How To Work with JSON in MySQL | DigitalOcean
March 10, 2026 - MySQL 5.7.8 and later support a native JSON data type, so you can store and query semi-structured data without leaving your relational database. Use JSON_OBJECT, JSON_ARRAY, and JSON_MERGE_PRESERVE to build JSON in SQL; use JSON_EXTRACT (or the -> operator) to read and filter on JSON paths. ...
🌐
Database Guide
database.guide › json_set-insert-or-update-values-in-a-json-document-in-mysql
JSON_SET() – Insert or Update Values in a JSON Document in MySQL
SELECT JSON_SET('[1, 2, 3]', '$[3]', 4) AS 'Result'; ... If the existing value is not an array, it is autowrapped as an array, then extended with the new value.
🌐
DataCamp
datacamp.com › doc › mysql › mysql-json-array
MySQL JSON_ARRAY() Function: Usage & Examples
The `JSON_ARRAY()` function in MySQL creates a JSON array from a list of values.
🌐
MySQL Tutorial
mysqltutorial.org › home › mysql json › mysql json_array() function
MySQL JSON_ARRAY() Function
November 23, 2023 - In MySQL, the JSON_ARRAY() function is used to create a JSON array from a list of values.
🌐
MySQL
dev.mysql.com › doc › refman › 8.0 › en › json.html
MySQL :: MySQL 8.0 Reference Manual :: 13.5 The JSON Data Type
March 18, 2021 - The input column and the target ... jcol1 = JSON_SET(jcol2, '$.a', 100) cannot be performed as a partial update. The update can use nested calls to any of the functions listed in the previous item, in any combination, as long as the input and target columns are the same. All changes replace existing array or object ...
🌐
MySQL
dev.mysql.com › doc › refman › 8.0 › en › json-modification-functions.html
MySQL :: MySQL 8.0 Reference Manual :: 14.17.4 Functions That Modify JSON Values
February 5, 2020 - If a path selects a scalar or object value, that value is autowrapped within an array and the new value is added to that array. Pairs for which the path does not identify any value in the JSON document are ignored. mysql> SET @j = '["a", ["b", "c"], "d"]'; mysql> SELECT JSON_ARRAY_APPEND(@j, '$[1]', 1); +----------------------------------+ | JSON_ARRAY_APPEND(@j, '$[1]', 1) | +----------------------------------+ | ["a", ["b", "c", 1], "d"] | +----------------------------------+ mysql> SELECT JSON_ARRAY_APPEND(@j, '$[0]', 2); +----------------------------------+ | JSON_ARRAY_APPEND(@j, '$[0]',
🌐
MySQL
dev.mysql.com › doc › refman › 9.6 › en › json.html
MySQL :: MySQL 9.6 Reference Manual :: 13.5 The JSON Data Type
The input column and the target ... jcol1 = JSON_SET(jcol2, '$.a', 100) cannot be performed as a partial update. The update can use nested calls to any of the functions listed in the previous item, in any combination, as long as the input and target columns are the same. All changes replace existing array or object ...
Find elsewhere
Top answer
1 of 1
5

The result from JSON_SEARCH() is not a valid JSON path. It's quoted, like a JSON string value. Notice the double-quotes:

mysql> select json_search(config, 'one', 'Infrastructure') 
  from table_config;
+----------------------------------------------+
| json_search(config, 'one', 'Infrastructure') |
+----------------------------------------------+
| "$.deploy[0]"                                |
+----------------------------------------------+

So if you try to use it as the path argument in JSON_SET(), it doesn't work:

mysql> select json_set(config, json_search(config, 'one', 'Infrastructure'), 'Infrastructure')
  from table_config;
ERROR 3143 (42000): Invalid JSON path expression. The error is around character position 1.

To use this as a JSON path, you have to remove those quotes:

mysql> select json_unquote(json_search(config, 'one', 'Infrastructure')) 
  from table_config;
+------------------------------------------------------------+
| json_unquote(json_search(config, 'one', 'Infrastructure')) |
+------------------------------------------------------------+
| $.deploy[0]                                                |
+------------------------------------------------------------+

Then you can use it in a call to JSON_SET():

mysql> select json_set(config, json_unquote(json_search(config, 'one', 'Infrastructure')), 'Infrastructure') 
  from table_config;
+------------------------------------------------------------------------------------------------+
| json_set(config, json_unquote(json_search(config, 'one', 'Infrastructure')), 'Infrastructure') |
+------------------------------------------------------------------------------------------------+
| {"deploy": ["Infrastructure", "API Security"], "operate": ["Pen Testing", "Bug Bounty"]}       |
+------------------------------------------------------------------------------------------------+
🌐
Sqliz
sqliz.com › mysql-ref › json_set
MySQL JSON_SET() Function
If the parameter path is not a valid path expression or contains * or **, MySQL will give an error. Let’s first create a JSON document that is a JSON object: ... +----------------------------------------------+ | JSON_SET(@obj, '$.x', '10', '$.y', '[1, 2]') | +----------------------------------------------+ | {"x": "10", "y": "[1, 2]"} | +----------------------------------------------+ We found that although we has inserted or updated the data, there are still some problems, that is, the array [1, 2] became "[1, 2]" that is a JSON string not a JSON array.
🌐
MySQL
dev.mysql.com › doc › refman › 9.7 › en › json-modification-functions.html
MySQL :: MySQL 9.7 Reference Manual :: 14.17.4 Functions That Modify JSON Values
If a path selects a scalar or object value, that value is autowrapped within an array and the new value is added to that array. Pairs for which the path does not identify any value in the JSON document are ignored. mysql> SET @j = '["a", ["b", "c"], "d"]'; mysql> SELECT JSON_ARRAY_APPEND(@j, '$[1]', 1); +----------------------------------+ | JSON_ARRAY_APPEND(@j, '$[1]', 1) | +----------------------------------+ | ["a", ["b", "c", 1], "d"] | +----------------------------------+ mysql> SELECT JSON_ARRAY_APPEND(@j, '$[0]', 2); +----------------------------------+ | JSON_ARRAY_APPEND(@j, '$[0]',
🌐
MySQL
dev.mysql.com › doc › refman › 5.7 › en › json-modification-functions.html
MySQL :: MySQL 5.7 Reference Manual :: 12.17.4 Functions That Modify JSON Values
March 18, 2019 - If a path selects a scalar or object value, that value is autowrapped within an array and the new value is added to that array. Pairs for which the path does not identify any value in the JSON document are ignored. mysql> SET @j = '["a", ["b", "c"], "d"]'; mysql> SELECT JSON_ARRAY_APPEND(@j, '$[1]', 1); +----------------------------------+ | JSON_ARRAY_APPEND(@j, '$[1]', 1) | +----------------------------------+ | ["a", ["b", "c", 1], "d"] | +----------------------------------+ mysql> SELECT JSON_ARRAY_APPEND(@j, '$[0]', 2); +----------------------------------+ | JSON_ARRAY_APPEND(@j, '$[0]',
🌐
MySQL
dev.mysql.com › doc › refman › 8.4 › en › json-modification-functions.html
MySQL :: MySQL 8.4 Reference Manual :: 14.17.4 Functions That Modify JSON Values
If a path selects a scalar or object value, that value is autowrapped within an array and the new value is added to that array. Pairs for which the path does not identify any value in the JSON document are ignored. mysql> SET @j = '["a", ["b", "c"], "d"]'; mysql> SELECT JSON_ARRAY_APPEND(@j, '$[1]', 1); +----------------------------------+ | JSON_ARRAY_APPEND(@j, '$[1]', 1) | +----------------------------------+ | ["a", ["b", "c", 1], "d"] | +----------------------------------+ mysql> SELECT JSON_ARRAY_APPEND(@j, '$[0]', 2); +----------------------------------+ | JSON_ARRAY_APPEND(@j, '$[0]',
🌐
Oracle
docs.oracle.com › cd › E17952_01 › mysql-8.0-en › json-utility-functions.html
14.17.8 JSON Utility Functions
October 25, 2025 - The effects of successive partial updates on this free space are cumulative, as shown in this example using JSON_SET() to reduce the space taken up by the value having key b (and making no other changes): mysql> UPDATE jtable -> SET jcol = JSON_SET(jcol, "$.a", 10, "$.b", "wx", "$.c", 1); Query OK, 1 row affected (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> SELECT JSON_STORAGE_FREE(jcol) FROM jtable; +-------------------------+ | JSON_STORAGE_FREE(jcol) | +-------------------------+ | 16 | +-------------------------+ 1 row in set (0.00 sec)
🌐
MySQL
dev.mysql.com › doc › refman › 8.4 › en › json-creation-functions.html
MySQL :: MySQL 8.4 Reference Manual :: 14.17.2 Functions That Create JSON Values
Two aggregate functions generating JSON values are available. JSON_ARRAYAGG() returns a result set as a single JSON array, and JSON_OBJECTAGG() returns a result set as a single JSON object.
🌐
Oracle
docs.oracle.com › cd › E17952_01 › mysql-8.0-en › json.html
13.5 The JSON Data Type
February 9, 2026 - JSON_ARRAY() takes a (possibly empty) list of values and returns a JSON array containing those values: mysql> SELECT JSON_ARRAY('a', 1, NOW()); +----------------------------------------+ | JSON_ARRAY('a', 1, NOW()) | +----------------------------------------+ | ["a", 1, "2015-07-27 ...
🌐
Database Star
databasestar.com › mysql-json
JSON in MySQL: The Ultimate Guide | Database Star: Home
October 27, 2020 - The JSON_ARRAY function in MySQL lets you easily specify array data when inserting JSON data in MySQL.
🌐
Medium
medium.com › @bao.character › useful-mysql-function-for-json-object-json-set-388eda50aaf4
Useful MySQL Function for JSON Object — JSON_SET | by Gary Bao | Medium
July 2, 2024 - The function can take multiple path and val pairs to perform multiple insertions or updates in a single call. ... UPDATE your_table SET your_json_column = JSON_SET(your_json_column, '$."31"', 2) WHERE your_condition;