Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

JSON_REPLACE with MySQL

Hello,

I have a problem with JSON_REPLACE.

I need to replace all the keys named unit without knowing the exact path.

update table set params = json_replace(params, '$.*.unit', 'new unit') where condition = true;

I have tried with a * caracter, but it doesn't work.

It is possiblr to match any subkey without knowing the exact path ?

Thanks for your help.

V

0 likes
1 reply
vincent15000's avatar

I have chosen to use REPLACE() method instead of JSON_REPLACE, it works fine.

But if there's a solution to use JSON_REPLACE as I needed, it's always interesting to know how to do.

Please or to participate in this conversation.