https://github.com/xavierjefferson/snork.jsoncommentstripper
Strip comments from JSON. Lets you use comments in your JSON files!
https://github.com/xavierjefferson/snork.jsoncommentstripper
Last synced: about 1 month ago
JSON representation
Strip comments from JSON. Lets you use comments in your JSON files!
- Host: GitHub
- URL: https://github.com/xavierjefferson/snork.jsoncommentstripper
- Owner: xavierjefferson
- License: mit
- Created: 2024-06-01T20:53:14.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2024-06-02T07:15:50.000Z (12 months ago)
- Last Synced: 2025-02-13T07:39:52.858Z (3 months ago)
- Language: C#
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Snork.JsonCommentStripper
[](https://www.nuget.org/packages/Snork.JsonCommentStripper/)> Strip comments from JSON. Lets you use comments in your JSON files!
This is now possible:
```js
{
// Rainbows
"unicorn": /* ❤ */ "cake"
}
```It will replace single-line comments `//` and multi-line comments `/**/` with whitespace. This allows JSON error positions to remain as close as possible to the original source.
## Usage
```c#
using Snork.JsonCommentStripper;string json = @"{
// Rainbows
\"unicorn\": /* ❤ */ \"cake\"
}";Console.WriteLine(Stripper.Execute(json));
//=> {unicorn: 'cake'}
```## API
### Stripper.StripJsonComments(string input, StripperOptions options = null)
#### input
Type: `string`
Accepts a string with JSON and returns a string without comments.
#### options
Type: StripperOptions
##### TrailingCommas
Type: `boolean`\
Default: `false`Strip trailing commas in addition to comments.
##### ReplaceWithWhiteSpace
Type: `boolean`\
Default: `true`Replace comments and trailing commas with whitespace instead of stripping them entirely.
## Related
This code is adapted from a JavaScript version by [Sindre Sorhus](https://github.com/sindresorhus).