@biu/jsonlint

lint your json, report all errors at once

Usage no npm install needed!

<script type="module">
  import biuJsonlint from 'https://cdn.skypack.dev/@biu/jsonlint';
</script>

README

jsonlint

Node.js CI status npm downloads npm

Features

  • ⚔️ Lint all errors at once
  • 🌈Human-friendly, intuitive message to stdout
  • 🚀Smaller than ESLint

Screenshot

Installation

For NPM users

npm i @biu/jsonlint

for yarn users

yarn add @biu/jsonlint

API

const { lint, format } = require( '@biu/jsonlint' )

const result = lint( string, options )
const prettied = format( result )

console.log( result.codeframe )
// or
// console.log( prettied )

result looks like

{
  source: '', // source code
  errors: [], // with keys: `{ line, column, message, severity }`
  comments: [], // with keys: `{ start: { line, column }, end: { line, column } }`
  codeframe: '', // codeframe with error locations
}

prettied looks like Screenshot

You can log message to stdout by using console.log( result.codeframe ) or console.log( prettied )

string

Type: String

options.allowComments

By default it will report comments as error, if you want to remove comment from errors, just set allowComments to true

Difference with try/catch + JSON.parse

JSON.parse is not fault tolerant, so it cannot continue after seeing first error, while in this library we use a fault tolerant parser inside to avoid this situation

License

MIT