https://github.com/duzun/require-strip-json-comments
Require .json files which contain comments
https://github.com/duzun/require-strip-json-comments
Last synced: 5 months ago
JSON representation
Require .json files which contain comments
- Host: GitHub
- URL: https://github.com/duzun/require-strip-json-comments
- Owner: duzun
- License: mit
- Created: 2016-03-07T16:46:54.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-01-17T14:01:17.000Z (over 5 years ago)
- Last Synced: 2024-11-14T10:15:42.300Z (11 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# require-strip-json-comments [](https://travis-ci.org/duzun/require-strip-json-comments)
Require .json files with comments.
For advanced JSON syntax I recomend using [require-json5](https://www.npmjs.com/package/require-json5),
which can load JSON with trailing commas, unquoted keys, hex numbers, comments, and more.## Install
```sh
npm i require-strip-json-comments
```## Usage
1) Load a JSON file which contains comments
```js
var requireJSON = require('require-strip-json-comments');
var config = requireJSON("./config.json");
```2) Parse a JSON string which contains comments
```js
var requireJSON = require('require-strip-json-comments');
var config = requireJSON.parse('{"name": /*a very important option*/ "value"}');
```3) Replace `require()`
```js
require('require-strip-json-comments').replace_require();
var config = require("./config");
```4) Replace `JSON.parse()`
```js
require('require-strip-json-comments').replace_JSON();
var config = JSON.parse('{"name": /*a very important option*/ "value"}');
```5) Replace `require()` and `JSON.parse()`
```js
require('require-strip-json-comments').replace();
// ...
```