Fixing a Typo in JSON in MySQL

May 2020

Let's say you have the table Documents which has a column content that contains a JSON. And while writing your application logic, you've accidentally misspelled a word in a key of a JSON property and now the word is misspelled in all your stored Document entries. Fixing such a typo in a JSON property key can actually be quite easy:


UPDATE Documents
SET Documents.content = REPLACE(Documents.content, '\"myTpyo\"', '\"myTypo\"')
    

Like this, you'll replace all occurrences of that "myTpyo" with the correct string "myTypo". Note that it's important to put the quotes around the string, so you don't accidentally match the string in a text field. Even though, who knows, maybe those occurrences should be fixed as well? In that case just drop the quotes:


UPDATE Documents
SET Documents.content = REPLACE(Documents.content, 'myTpyo', 'myTypo')
    
Dear Devs: You can help Ukraine🇺🇦. I opted for (a) this message and (b) a geo targeted message to Russians coming to this page. If you have a blog, you could do something similar, or you can link to a donations page. If you don't have one, you could think about launching a page with uncensored news and spread it on Russian forums or even Google Review. Or hack some russian servers. Get creative. #StandWithUkraine 🇺🇦
Dear russians🇷🇺. I am a peace loving person from Switzerland🇨🇭. It is without a doubt in my mind, that your president, Vladimir Putin, has started a war that causes death and suffering for Ukrainians🇺🇦 and Russians🇷🇺. Your media is full of lies. Lies about the casualties, about the intentions, about the "Nazi Regime" in Ukraine. Please help to mobilize your people against your leader. I know it's dangerous for you, but it must be done!