Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dnmfarrell/strip-json-comments
Removes JSON comments from jsonc text
https://github.com/dnmfarrell/strip-json-comments
golang json jsonc linux perl
Last synced: about 1 month ago
JSON representation
Removes JSON comments from jsonc text
- Host: GitHub
- URL: https://github.com/dnmfarrell/strip-json-comments
- Owner: dnmfarrell
- License: mit
- Created: 2022-03-13T13:55:20.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-14T14:08:53.000Z (almost 3 years ago)
- Last Synced: 2024-06-21T19:04:19.374Z (6 months ago)
- Topics: golang, json, jsonc, linux, perl
- Language: Go
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Strip JSON Comments
-------------------
Strips single line `//` and block `/* */` comments from .jsonc text:```
echo '[1, /* strip this comment */ 2, 3]' | ./strip-jsonc
[1, 2, 3]
```### Comment characters are replaced with spaces
To preserve line and column locations of the remaining JSON text.### Block comments do not nest
JSONC doesn't have a spec but its block comments have been [described](https://code.visualstudio.com/docs/languages/json#_json-with-comments) as behaving like JavaScript, i.e. they do not nest.### Trailing commas are not removed
Some JSONC parsers support trailing commas, but as `strip-jsonc` is line-oriented, it does not have an option to remove trailing commas.### Test input
This repo contains a test input file called `test.jsonc` which exercises the different cases of embedding comments in JSON.### Perl
The `strip-jsonc` script is written in Perl and designed to be fast and compatible with any version of Perl 5.### Go
There is a golang variant of the strip-jsonc script which has the same behavior as the Perl script but can be 3-4x faster for large inputs. It can be compiled with go build:```
go build gostrip-jsonc.go
```