Remove // line comments and block comments from JSON-with-comments,
leaving everything else byte-for-byte intact.
This has to be string-aware rather than a regex: spec examples are full of
values like "https://w3id.org/zcap/v1", and a naive // strip would
truncate every one of them. Comment starts are only recognised outside of
string literals, with backslash escapes honoured.
Use this on any example whose mediaType is "application/jsonc".
Parameters
text: string
JSON text that may contain // or block comments.
Returns string
The same text with comments replaced by whitespace, ready for JSON.parse.
Remove
//line comments and block comments from JSON-with-comments, leaving everything else byte-for-byte intact.This has to be string-aware rather than a regex: spec examples are full of values like
"https://w3id.org/zcap/v1", and a naive//strip would truncate every one of them. Comment starts are only recognised outside of string literals, with backslash escapes honoured.Use this on any example whose
mediaTypeis"application/jsonc".