codenothing / jsonlint

JSON Linter that allows comments
http://codenothing.github.com/jsonlint/
MIT License
32 stars 12 forks source link

NPM version Test Runner Code Climate

JSONLint

JSONLint is a JSON Linter that allows for comments in your JSON Files.

Installation

For use with NodeJS, use NPM

$ npm install -g json-lint

For use in browser environments, include the script tag

<script type="text/javascript" src="https://github.com/codenothing/jsonlint/raw/main/jsonlint.js"></script>

Usage

// Require it for NodeJS environment
var JSONLint = require("json-lint");

// Run the JSON string through the linter
var lint = JSONLint(json, options);

// Do something with the error
if (lint.error) {
  lint.error; // Error Message
  lint.line; // Line number in json file where error was found
  lint.character; // Character of line in json file where error was found
}

JSONLint takes two arguments, and throws an error if found.

Options

There is currently only 1 option that is handled: comments, which defaults to true if not set.