Creating an Angular2 app, I want to maintain a configuration file (with comments) that gets loaded at runtime per Matt Tester's answer to this question, except I'm using JSONC in lieu of JSON, as comments are important in the configuration file, (at least in the copy that gets maintained in the source).
Note: VS Code has a "JSON with Comments" (JSONC) mode. JSONC mode is used for the VS Code configuration files such as tsconfig*.json and launch.json. When in the JSONC mode, you can use single line (//) as well as block comments (/* */). The current editor mode is indicated in the editor's Status Bar. This is not a novel concept, so I don't think I'm just crazy.
The problem is that a generic http.get() (e.g. this.http.get('../assets/config.json').subscribe(_ => { console.log('get() complete'); });
seems to run JSON.parse() automatically, and thus naturally throws an error when it encounters a comment in the config.json file that it retrieves.
My first inclination was to figure out what HTTP header(s) to add to the get() to make it expect plain text, and then execute some method to strip the comments out to turn it into proper JSON before processing it, but that seems hackish.
What is the correct approach to solve this? Is there some means to 'decomment' the JSONC file as it gets served up? Or some script to create a scrubbed copy at run-time and map requests for it to the scrubbed version? Or is there a way to replace JSON.parse() with some (I suppose) JSONC.parse()? Or is there some other idiomatic way of handling this?