I would advise against constructing JSON strings with regular expressions, as well as parsing CSV with them. These syntaxes are more convoluted (CSV can have quotes to escape commas in values, JSON is recursive, and rules of character escaping are different between these).
This sort of approach might be fine for a quick one-off job, but using it for more than that is asking for trouble.
It's just like this iconic Stack Overflow answer: stackoverflow.com/a/1732454
Thanks for your advise. I absolutely share your views, so I have to ask if you actually read the first section about „not to use it in production“? ;)
I even use the results of such an operation only for testing purposes.
BTW, I just added a disclaimer, just in case what I wrote here could be misunderstood. I don’t mean something like „using regex is dangerous but I will show you how to do it right“. That’s absolutely not what I intended.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.