An open API service indexing awesome lists of open source software.

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.

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 | [![DotNetJsonCheck.Tool NuGet version](https://img.shields.io/nuget/v/DotNetJsonCheck.Tool?logo=nuget&style=flat-square)][nuget-dnjc-tool] |
| DotNetJsonCheck | [![DotNetJsonCheck NuGet version](https://img.shields.io/nuget/v/DotNetJsonCheck?logo=nuget&style=flat-square)][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