const regex = /(?:(?=(?&V_Obj)){|(?!^)\G(?&Sep_Obj)\s*)(?:(?&V_KeyVal)(?&Sep_Obj))*?\s*(?&Str)\s*:\s*\K(?&Numb)(?(DEFINE)(?<Sep_Ary>\s*(?:,(?!\s*[}\]])|(?=\])))(?<Sep_Obj>\s*(?:,(?!\s*[}\]])|(?=})))(?<Er_Obj>(?>{(?:\s*(?&Str)(?:\s*:(?:\s*(?:(?&Er_Value)|(?<Er_Ary>\[(?:\s*(?:(?&Er_Value)|(?&Er_Ary)|(?&Er_Obj))(?:(?&Sep_Ary)|(*ACCEPT)))*(?:\s*\]|(*ACCEPT)))|(?&Er_Obj))(?:(?&Sep_Obj)|(*ACCEPT))|(*ACCEPT))|(*ACCEPT)))*(?:\s*}|(*ACCEPT))))(?<Er_Value>(?>(?&Numb)|(?>true|false|null)|(?&Str)))(?<Str>(?>"[^\\"]*(?:\\[\s\S][^\\"]*)*"))(?<Numb>(?>[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?|(?:[eE][+-]?\d+)))(?<V_KeyVal>(?>\s*(?&Str)\s*:\s*(?&V_Value)\s*))(?<V_Value>(?>(?&Numb)|(?>true|false|null)|(?&Str)|(?&V_Obj)|(?&V_Ary)))(?<V_Ary>\[(?>\s*(?&V_Value)(?&Sep_Ary))*\s*\])(?<V_Obj>{(?>(?&V_KeyVal)(?&Sep_Obj))*\s*}))/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:(?=(?&V_Obj)){|(?!^)\\G(?&Sep_Obj)\\s*)(?:(?&V_KeyVal)(?&Sep_Obj))*?\\s*(?&Str)\\s*:\\s*\\K(?&Numb)(?(DEFINE)(?<Sep_Ary>\\s*(?:,(?!\\s*[}\\]])|(?=\\])))(?<Sep_Obj>\\s*(?:,(?!\\s*[}\\]])|(?=})))(?<Er_Obj>(?>{(?:\\s*(?&Str)(?:\\s*:(?:\\s*(?:(?&Er_Value)|(?<Er_Ary>\\[(?:\\s*(?:(?&Er_Value)|(?&Er_Ary)|(?&Er_Obj))(?:(?&Sep_Ary)|(*ACCEPT)))*(?:\\s*\\]|(*ACCEPT)))|(?&Er_Obj))(?:(?&Sep_Obj)|(*ACCEPT))|(*ACCEPT))|(*ACCEPT)))*(?:\\s*}|(*ACCEPT))))(?<Er_Value>(?>(?&Numb)|(?>true|false|null)|(?&Str)))(?<Str>(?>"[^\\\\"]*(?:\\\\[\\s\\S][^\\\\"]*)*"))(?<Numb>(?>[+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)(?:[eE][+-]?\\d+)?|(?:[eE][+-]?\\d+)))(?<V_KeyVal>(?>\\s*(?&Str)\\s*:\\s*(?&V_Value)\\s*))(?<V_Value>(?>(?&Numb)|(?>true|false|null)|(?&Str)|(?&V_Obj)|(?&V_Ary)))(?<V_Ary>\\[(?>\\s*(?&V_Value)(?&Sep_Ary))*\\s*\\])(?<V_Obj>{(?>(?&V_KeyVal)(?&Sep_Obj))*\\s*}))', 'gm')
const str = `{
"first_name":"sample",
"last_name": "lastname",
"integer" : 100,
"float" : 1555.20,
"createddate":"2015-06-25 09:57:28",
"asder" :
[
200,
100,
{
"nother1" : "here",
"digi1" : 900e10,
"nother1" : "here",
"digi2" : 3.14
},
400,
37
]
}`;
const subst = `"$0"`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions