Skip to content

Like ESLint but focus on json lint, also with a smaller size

License

Notifications You must be signed in to change notification settings

fengzilong/jsonlint

Repository files navigation

jsonlint

Node.js CI status npm downloads npm

Screenshot

Features

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

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 )

prettied looks like Screenshot

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 and syntax highlight
}

string

Type: String

options.allowComments

By default it reports all comments as error, if you want to remove comment from errors, set allowComments to true

Difference with try/catch + JSON.parse

JSON.parse is not fault tolerant, so it cann't continue after seeing first error, while this library using a fault tolerant parser to avoid this

License

MIT