Monday, April 03, 2023

[Regex] Regular Expression to find unescaped double-quotes in JSON

So here we are again. Another couple of years have passed. Maybe this year I'll be more forthcoming with content. Maybe I can log what I do at the office here, though without all the WPAdmin passwords.

Today I had exported the entire WooCommerce inventory of a customer as JSON but found that there were embedded double-quotes that weren't properly escaped and so were messing up the tools I use for JSON traversal and extraction.

I used Notepad++ for most text editing (when I'm not using Visual Studio Code) and I cooked up this regular expression to help me find double quotes:

 [^:,]\s"\w+

That looks for a character that isn't a colon or comma, followed by a space followed by a double-quote followed by one or more word-building characters.  

No comments: