Below is a JSON structure that I am working with:
'use strict';
// some comment is going to be here
module.exports = {
property1: 'value1',
property2: 999,
};
I am looking to remove the property2: 999,
from the JSON. I attempted to achieve this using the following method:
var x = " 'use strict';\n"
+ " // some comment is going to be here\n"
+ " module.exports = {\n"
+ " property1: 'value1',\n"
+ " property2: 999,\n"
+ " };\n";
alert(x.replace(/property2: 999,/, ""));
DEMO
I want to find a better way to remove the specified property and its value from the JSON structure. The aim is to ensure we are targeting it accurately within the JSON object. Here's the desired outcome:
'use strict';
// some comment is going to be here
module.exports = {
property1: 'value1',
};