@biu/jsonlint

2.0.0 • Public • Published

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

/@biu/jsonlint/

    Package Sidebar

    Install

    npm i @biu/jsonlint

    Weekly Downloads

    2

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    10.5 kB

    Total Files

    5

    Last publish

    Collaborators

    • fengzilong