https://github.com/prantlf/v-jsonlint
JSON/JSONC/JSON5 validator and pretty-printer.
https://github.com/prantlf/v-jsonlint
json json5 jsonc jsonlint lint validate
Last synced: 5 months ago
JSON representation
JSON/JSONC/JSON5 validator and pretty-printer.
- Host: GitHub
- URL: https://github.com/prantlf/v-jsonlint
- Owner: prantlf
- License: mit
- Created: 2023-06-25T09:21:53.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-11-16T04:18:00.000Z (6 months ago)
- Last Synced: 2024-11-16T05:19:09.779Z (6 months ago)
- Topics: json, json5, jsonc, jsonlint, lint, validate
- Language: V
- Homepage:
- Size: 60.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonlint
[JSON]/[JSONC]/[JSON5] validator and pretty-printer.
* Uses a [fast] recursive descent parser written in V.
* Shows detailed [error messages](#errors) with location context.
* Optionally supports [JSONC] - ignores single-line and multi-line JavaScript-style comments treating them as whitespace and also trailing commas in arrays ans objects.
* Partially supports [JSON5] - allows single-quoted strings. (JSON5 is work in progress.)
* Offers both condensed and prettified [JSON] output.Uses [prantlf.json].
## Synopsis
Check the syntax of a file `config.json`, append a trailing line break to the JSON output, make the output more readable by indentation and overwrite the original file with the formatted output:
jsonlint config.json -lpw
Check a file read from standard input and print it formatted to standard output, as condensed as possible, no trailing line break:
cat config.yaml | jsonlint > config.json
## Usage
jsonlint [options] [ ...]
read the JSON/JSONC/JSON5 input from a file
Options:
-o|--output write the JSON output to a file
-m|--mode parse in the mode "json", "jsonc", or "json5"
-w|--overwrite overwrite the input file with the formatted output
-k|--check check the syntax only, no output
-a|--compact print error messages on a single line
-t|--trailing-commas insert trailing commas to arrays and objects
-s|--single-quotes format single-quoted instead of double-quoted strings
--escape-slashes escape slashes by by prefixing them with a backslash
--escape-unicode escape multibyte Unicode characters with \u literals
-l|--line-break append a line break to the JSON output
-p|--pretty print the JSON output with line breaks and indented
-V|--version print the version of the executable and exit
-h|--help print the usage information and exitIf no input file is specified, it will be read from standard input.
If multiple files are specified and file overwriting is not enabled,
the files will be only checked and their names printed out.## Errors
The error output is based on the [error messages] provided by [prantlf.json]:
❯ jsonlint .vscode/launch.json
.vscode/launch.json:3:3: Expected '"' but got "/" when parsing an object key:
2 | {
3 | // Use IntelliSense …
| ^Compact output when checking many files:
❯ v run jsonlint.v .vscode/*.json -a
.vscode/launch.json:3:3: Expected '"' but got "/" when parsing an object key
.vscode/settings.json: OK
.vscode/tasks.json:3:3: Expected '"' but got "/" when parsing an object keyFixing the errors by enabling [JSONC]:
❯ jsonlint .vscode/*.json -m jsonc
.vscode/launch.json: OK
.vscode/settings.json: OK
.vscode/tasks.json: OK## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.
## License
Copyright (c) 2023-2024 Ferdinand Prantl
Licensed under the MIT license.
[prantlf.json]: https://github.com/prantlf/v-json
[JSON]: https://www.json.org/
[JSONC]: https://changelog.com/news/jsonc-is-a-superset-of-json-which-supports-comments-6LwR
[JSON5]: https://spec.json5.org/
[fast]: https://github.com/prantlf/v-json#performance
[error messages]: https://github.com/prantlf/v-json#errors