Looking to remove JSON comments using JavaScript? I believe a regular expression would be the most efficient method.
{
"field": { // comments
"n": 1 /* multi-line ...
comments */
},
"field2": " // comments in string , /* here */ "
}
This should be effective for the provided example.
Note: comments within strings should not be deleted.
Update: I understand that comments in JSON are not standard, but for simplicity, I want to include them and then remove them. Many tools can handle parsing JSON with comments.
Update 2: The example above is actually a string, I failed to mention that (apologies), and I see some responses assuming it is JavaScript code.
Update 3: I once again forgot to enclose key names in double quotes, the question has been updated.