jsonlint
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
try/catch + JSON.parse
Difference with 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