https://github.com/chwarr/dnjc
.NET JSON Check, dnjc, is a command line tool to check for JSON syntax errors using the System.Text.Json parsers.
https://github.com/chwarr/dnjc
dotnet dotnet-core emacs flycheck json
Last synced: about 2 months ago
JSON representation
.NET JSON Check, dnjc, is a command line tool to check for JSON syntax errors using the System.Text.Json parsers.
- Host: GitHub
- URL: https://github.com/chwarr/dnjc
- Owner: chwarr
- License: agpl-3.0
- Created: 2020-05-13T08:21:10.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-03T21:09:03.000Z (almost 2 years ago)
- Last Synced: 2025-02-02T05:25:42.241Z (over 1 year ago)
- Topics: dotnet, dotnet-core, emacs, flycheck, json
- Language: C#
- Homepage:
- Size: 105 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
README
# dnjc, .NET JSON Check
[.NET JSON Check][dnjc], `dnjc`, is a command line tool to check for JSON
syntax errors using the [`System.Text.Json`][stj] parsers.
```powershell
PS> Get-Content "good.json" | dnjc
# Nothing wrong: no output
PS> Get-Content "bad.json" | dnjc
6 2 '}' is an invalid start of a value.
```
The source code [is hosted on GitHub](https://github.com/chwarr/dnjc).
## Install
`dnjc` can be installed as a [.NET global tool][dotnet-global-tools]:
```powershell
dotnet tool install --global DotNetJsonCheck.Tool
```
If this is the first .NET global tool you've installed, you may need to
restart your shell/console for it to pick up the changes to your PATH.
## Versions
The current versions of the tool and the library that powers it are shown
below.
| Package | Version |
|---------|---------|
| DotNetJsonCheck.Tool | [][nuget-dnjc-tool] |
| DotNetJsonCheck | [][nuget-dnjc] |
## Invocation
After installing, invoke it, giving it the JSON you want to check on
standard input. Using PowerShell, this is something like:
```powershell
Get-Content "input.json" | dnjc
```
Other shells, like Bash, CMD, and Zsh can use redirection:
```bash
dnjc M-x `package-install-file` RET
`/path/to/where/you/downloaded/flycheck-dnjc.el`
If you use [`use-package`][use-package] to manage your packages, add this to
your `.emacs` file:
```elisp
(use-package flycheck-dnjc
:config (setup-flycheck-dnjc))
```
If you aren't using any package managers, make sure that
`flycheck-dnjc` in on your load-path and add:
```elisp
(require 'flycheck-dnjc)
(setup-flycheck-dnjc)
```
## Error reporting
Any errors encountered will be written to standard out, one per line. Each
line has the format
```
LEVELLINECOLUMNMESSAGE
```
* LEVEL: the severity of the issue. Currently only "Error" is used.
* LINE: the 1-based line number where the error occurred or started.
* COLUMN: the 0-based byte offset into the line where the error occurred.
* MESSAGE: the detailed error message.
If LINE or COLUMN cannot be determined, they will be empty.
Additional columns may be added in the future at the end. Ensure your
parsing can handle this.
The exit code of `dnjc` will be
* 0: JSON parsed successfully
* 1: invalid arguments
* 2: errors processing the JSON
* 126: catastrophic failure
## To Do
Things that I want to do, in rough priority order
1. Add option to require that the top-level value be an object, an array,
&c.
1. Use `package-upload-file` to create a hostable package archive?
## License
Copyright 2020, G. Christopher Warrington
dnjc is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License Version 3 as published by the
Free Software Foundation.
dnjc is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
details.
A copy of the GNU Affero General Public License Version 3 is included in the
file [LICENSE] at the root of the repository.
[dnjc]: https://www.thebluepolicebox.com/dnjc/
[dotnet-global-tools]: https://aka.ms/global-tools
[emacs]: https://www.gnu.org/software/emacs/
[flycheck-dnjc.el]: https://raw.githubusercontent.com/chwarr/dnjc/master/emacs/flycheck-dnjc.el
[flycheck]: https://www.flycheck.org/
[LICENSE]: https://github.com/chwarr/dnjc/blob/master/LICENSE
[mecj]: https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.json?view=dotnet-plat-ext-3.1
[nuget-dnjc-tool]: https://www.nuget.org/packages/DotNetJsonCheck.Tool/
[nuget-dnjc]: https://www.nuget.org/packages/DotNetJsonCheck/
[stj]: https://docs.microsoft.com/en-us/dotnet/api/system.text.json?view=netcore-3.1
[use-package]: https://github.com/jwiegley/use-package