Javascript Regular expression to wrap unquoted JSON Values and Keys with double quotes

72 views Asked by At

There is a string:

const str = "[{test1: 1, test2: {test3: 2, test4: { date: 2018-08-31T21:00:00+00:00 }, place: place place, time: 21:00, ...}}]"

How to make a valid object from it with RegEx? I tried the following:

str.replace(/:\s/g, ':').replace(/(['"])?(([а-яА-ЯЁёa-zA-Z0-9%\+\-\s_\$]+):([а-яёА-ЯЁa-zA-Z0-9%{}\+\-\s\:]+))(['"])?\s*/gi, '"$3":"$4"');

But this code does not allow for nesting.

0

There are 0 answers