Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fabiospampinato/tiny-jsonc
An absurdly small JSONC parser.
https://github.com/fabiospampinato/tiny-jsonc
comments json jsonc parse parser
Last synced: 2 months ago
JSON representation
An absurdly small JSONC parser.
- Host: GitHub
- URL: https://github.com/fabiospampinato/tiny-jsonc
- Owner: fabiospampinato
- License: mit
- Created: 2023-01-19T17:41:05.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-07T19:40:34.000Z (7 months ago)
- Last Synced: 2024-07-07T20:51:12.831Z (7 months ago)
- Topics: comments, json, jsonc, parse, parser
- Language: JavaScript
- Homepage:
- Size: 33.2 KB
- Stars: 16
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# Tiny JSONC
An absurdly small JSONC parser.
This library works simply by using regexes to strip out comments first and trailing commas second, in order to account for a trailing comma followed by a comment, and then just passing the output to `JSON.parse`.
If you need additional APIs to manipulate JSONC, better error messages, or a full-blown parser, I'd recommend using [`jsonc-simple-parser`](https://github.com/fabiospampinato/jsonc-simple-parser) instead.
## Install
```sh
npm install --save tiny-jsonc
```## Usage
```ts
import JSONC from 'tiny-jsonc';const source = `
{ // This is an example
"foo": 123,
/* TRAILING COMMAS */
"bar": [1, 2, 3,],
}
`;const result = {
foo: 123,
bar: [1, 2, 3]
};JSONC.parse ( source ); // => returns an object that's deeply equal to `result`
```## License
MIT © Fabio Spampinato