包详细信息

@prantlf/jsonlint

prantlf111.6kMIT16.0.0

JSON/CJSON/JSON5 parser, syntax and schema validator and pretty-printer.

json, validation, lint, jsonlint

自述文件

JSON Lint

Latest version Dependency status Code coverage

A JSON/CJSON/JSON5 parser, validator and pretty-printer with a command-line client. See it in action at https://prantlf.github.io/jsonlint/.

This is a fork of the original project (zaach/jsonlint) with the following enhancements:

  • Handles multiple files on the command line (by Greg Inman).
  • Walks directories recursively (by Paul Vollmer).
  • Provides 100% compatible interface to the native JSON.parse method.
  • Optionally ignores the leading UTF-8 byte-order mark (BOM).
  • Optionally recognizes JavaScript-style comments (CJSON) and single quoted strings (JSON5).
  • Optionally ignores trailing commas and reports duplicate object keys as an error.
  • Optionally checks that also the expected format matches, including sorted object keys.
  • Supports JSON Schema drafts 04, 06, 07, 2019-09 and 2020-12.
  • Supports JSON Type Definition.
  • Offers pretty-printing including comment-stripping and object keys without quotes (JSON5).
  • Prefers the native JSON parser if possible to run [10x faster than the custom parser].
  • Reports errors with rich additional information. From the JSON Schema validation too.
  • Consumes configuration from both command line and configuration files.
  • Implements JavaScript modules using UMD to work in Node.js, in a browser, everywhere.
  • Depends on up-to-date npm modules with no installation warnings.
  • Small size - 18.4 kB minified, 6.45 kB gzipped, 5.05 kB brotlied.

Note: In comparison with the original project, this package exports only the parse method; not the Parser object.

Integration to the favourite task loaders for JSON file validation is provided by the following NPM modules:

Synopsis

Check syntax of JSON files:

jsonlint -q data/*.json

Parse a JSON string:

const { parse } = require('@prantlf/jsonlint')
const data = parse('{"creative": false}')

Example of an error message:

Parse error on line 1, column 14:
{"creative": ?}
-------------^
Unexpected token "?"

Command-line Interface

Install jsonlint with npm, pnpm or yarn globally to be able to use the command-line interface in any directory:

npm i -g @prantlf/jsonlint
pnpm i -g @prantlf/jsonlint
yarn add --global @prantlf/jsonlint

Validate a single file:

jsonlint myfile.json

or pipe the JSON input into stdin:

cat myfile.json | jsonlint

or process all .json files in a directory and rewriting them with the pretty-printed output:

jsonlint --in-place --pretty-print mydir

By default, jsonlint will either report a syntax error with details or pretty-print the source if it is valid.

A more complex example: check all JSON files in a Node.js project, except for dependencies in node_modules, allow comments (CJSON) and trailing commas, forbid duplicated object keys, print processed files names on the console, print errors on a single line and if an error occurs, continue with other files:

jsonlint --comments --trailing-commas --no-duplicate-keys \
  --log-files --compact --continue '**/*.json' '!**/node_modules'

The same parameters can be passed from a configuration file:

{
  "comments": true,
  "trailing-commas": true,
  "duplicate-keys": false,
  "log-files": true,
  "compact": true,
  "continue": true,
  "patterns": ["**/*.json", "!**/node_modules"]
}

The input can be checked not only to be a valid JSON, but also to be formatted according to the coding standard. For example, check that there is a trailing li break in each JSON file, in addition to alphabetically sorted keys and no duplicate keys:

$ jsonlint -ksDr *.json

File: package.json
Formatted output differs
===================================================================
--- package.json.orig
+++ package.json
@@ -105,4 +105,4 @@
    "lint",
    "jsonlint"
  ]
-}
+}
\ No newline at end of file

Usage

Usage: jsonlint [options] [--] [<file, directory, pattern> ...]

Options

-f, --config <file>          read options from a custom configuration file
-F, --no-config              disable searching for configuration files
--ignore-proto-key           ignore occurrences of "__proto__" object key
--ignore-prototype-keys      ignore all keys from "Object.prototype"
-s, --sort-keys              sort object keys (not when prettifying)
--sort-keys-ignore-case      sort object keys ignoring the letter case
--sort-keys-locale <id>      locale identifier to sort object keys with
                             (or "default" for the system default)
--sort-keys-case-first <id>  order if only letter case is different
                             ("upper", "lower" and "false" are allowed)
--sort-keys-numeric          sort by numbers recognised in object keys
-E, --extensions <ext...>    file extensions to process for directory walk
                             (default: json, JSON)
-i, --in-place               overwrite the input files
-j, --diff                   print difference instead of writing the output
-k, --check                  check that the input is equal to the output
-t, --indent <num|char>      number of spaces or specific characters to use
                             for indentation or a string with whitespace
-c, --compact                compact error display
-M, --mode <mode>            set other parsing flags according to the format
                             of the input data (default: json)
-B, --bom                    ignore the leading UTF-8 byte-order mark
-C, --comments               recognize and ignore JavaScript-style comments
-S, --single-quoted-strings  support single quotes as string delimiters
-T, --trailing-commas        ignore trailing commas in objects and arrays
-D, --no-duplicate-keys      report duplicate object keys as an error
-V, --validate <file...>     JSON Schema file(s) to use for validation
-e, --environment <env>      which version of JSON Schema the validation
                             should use
-x, --context <num>          line number used as the diff context
                             (default: 3)
-l, --log-files              print only the parsed file names to stdout
-q, --quiet                  do not print the parsed json to stdout
-n, --continue               continue with other files if an error occurs
-p, --pretty-print           prettify the input instead of stringifying
                             the parsed object
-P, --pretty-print-invalid   force pretty-printing even for invalid input
-r, --trailing-newline       ensure a line break at the end of the output
-R, --no-trailing-newline    ensure no line break at the end of the output
--prune-comments             omit comments from the prettified output
--strip-object-keys          strip quotes from object keys if possible
--enforce-double-quotes      surrounds all strings with double quotes
--enforce-single-quotes      surrounds all strings with single quotes
--trim-trailing-commas       omit trailing commas from objects and arrays
--succeed-with-no-files      succeed (exit code 0) if no files were found
-v, --version                output the version number
-h, --help                   display help for command

You can use BASH patterns for including and excluding files (only files). Patterns are case-sensitive and have to use slashes as directory separators. A pattern to exclude from processing starts with "!".

Parsing mode can be "cjson" or "json5" to enable other flags automatically. If no files or directories are specified, stdin will be parsed. Environments for JSON Schema validation are "draft-04", "draft-06", "draft-07", "draft-2019-09" or "draft-2020-12". The environment may be prefixed with "json-schema-". JSON Type Definition can be selected by "rfc8927", "json-type-definition" or "jtd". If not specified, it will be "draft-07".

If you specify schemas using the "-V" parameter, you will have to separate files to test with "--".

Configuration

In addition to the command line parameters, the options can be supplied from the following files:

package.json, key jsonlint
.jsonlintrc
.jsonlintrc.json
.jsonlintrc.yaml
.jsonlintrc.yml
.jsonlintrc.js
.jsonlintrc.cjs
jsonlint.config.js
jsonlint.config.cjs

The automatic search for one of the following locations above can be disabled by the command-line parameter -F|--no-config. A concrete configuration file can be specified by the command-line parameter -f|--config [file]. Parameters from the command line will have higher priority than parameters from a configuration file.

The configuration is an object with the following properties, described above, which can be entered either in the kebab-case or in the camel-case:

Parameter Alias
patterns
ignore-proto-key ignoreProtoKey
ignore-prototype-keys ignorePrototypeKeys
sort-keys sortKeys
sort-keys-ignore-case sortKeysIgnoreCase
sort-keys-locale sortKeysLocale
sort-keys-case-first sortKeysCaseFirst
sort-keys-numeric sortKeysNumeric
extensions
in-place inPlace
diff
check
indent
compact
mode
bom
comments
single-quoted-strings singleQuotedStrings
trailing-commas trailingCommas
duplicate-keys duplicateKeys
validate
environment
log-files logFiles
quiet
continue
pretty-print prettyPrint
pretty-print-invalid prettyPrintInvalid
trailing-newline trailingNewline'
prune-comments pruneComments
strip-object-keys stripObjectKeys
enforce-double-quotes enforceDoubleQuotes
enforce-single-quotes enforceSingleQuotes
trim-trailing-commas trimTrailingCommas

The parameter config will be ignored in configuration files. The extra parameter patterns can be set to an array of strings with paths or patterns instead of putting them to the command line.

Module Interface

Install jsonlint with npm locally to be able to use the module programmatically:

npm i @prantlf/jsonlint -S

The only exported item is the parse method, which parses a string in the JSON format to a JavaScript object, array, or value:

const { parse } = require('@prantlf/jsonlint')
// Fails at the position of the character "?".
const data2 = parse('{"creative": ?}') // throws an error
// Succeeds returning the parsed JSON object.
const data3 = parse('{"creative": false}')
// Recognizes comments and single-quoted strings.
const data3 = parse("{'creative': true /* for creativity */}", {
  ignoreComments: true,
  allowSingleQuotedStrings: true
})

Have a look at the source of the on-line page to see how to use jsonlint on web page.

The exported parse method is compatible with the native JSON.parse method. The second parameter provides the additional functionality:

parse(input, [reviver|options])
Parameter Description
input text in the JSON format (string)
reviver converts object and array values (function)
options customize parsing options (object)

The parse method offers more detailed error information, than the native JSON.parse method and it supports additional parsing options:

Option Description
ignoreBOM ignores the leading UTF-8 byte-order mark (boolean)
ignoreComments ignores single-line and multi-line JavaScript-style comments during parsing as another "whitespace" (boolean)
ignoreTrailingCommas ignores trailing commas in objects and arrays (boolean)
allowSingleQuotedStrings accepts strings delimited by single-quotes too (boolean)
allowDuplicateObjectKeys allows reporting duplicate object keys as an error (boolean)
ignoreProtoKey ignore occurrences of the __proto__ object key (boolean)
ignorePrototypeKeys ignore all keys from Object.prototype (boolean)
mode sets multiple options according to the type of input data (string)
reviver converts object and array values (function)

The mode parameter (string) sets parsing options to match a common format of input data:

Mode Description
json complies to the pure standard JSON (default if not set)
cjson JSON with comments (sets ignoreComments)
json5 complies to JSON5 (sets ignoreComments, allowSingleQuotedStrings, ignoreTrailingCommas and enables other JSON5 features)

Schema Validation

You can validate the input against a JSON Schema using the lib/validator module. The compile method accepts either an earlier parsed JSON Schema or a string with it:

const { compile } = require('@prantlf/jsonlint/lib/validator')
const validate = compile('string with JSON Schema')
// Throws an error in case of failure.
const parsed = validate('string with JSON data')

If a string is passed to the compile method, the same options as for parsing JSON data can be passed as the second parameter. Compiling JSON Schema supports the same options as parsing JSON data too (except for reviver). They can be passed as the second (object) parameter. The optional second environment parameter (the default value is draft-07) ) can be passed either as a string or as an additional property in the options object too:

const validate = compile('string with JSON Schema', { environment: 'draft-2020-12' })

If you use external definitions in multiple schemas, you have to pass an array of all schemas to compile. The $id properties have to be set in each sub-schema according to the $ref references in the main schema. The main schema is usually sent as the first one to be compiled immediately, so that the errors in any sub-schema would be reported right away:

const validate = compile(['string with main schema', 'string with a sub-schema'])

Pretty-Printing

You can parse a JSON string to an array of tokens and print it back to a string with some changes applied. It can be unification of whitespace, reformatting or stripping comments, for example. (Raw token values must be enabled when tokenizing the JSON input.)

const { tokenize } = require('@prantlf/jsonlint')
const tokens = tokenize('string with JSON data', { rawTokens: true })
const { print } = require('@prantlf/jsonlint/lib/printer')
const output = print(tokens, { indent: 2 })

The tokenize method accepts options in the second optional parameter. See the tokenize method above for more information.

The print method accepts an object options as the second optional parameter. The following properties will be recognized there:

Option Description
indent count of spaces or the specific characters to be used as an indentation unit
pruneComments will omit all tokens with comments
stripObjectKeys will not print quotes around object keys which are JavaScript identifier names
enforceDoubleQuotes will surround all strings with double quotes
enforceSingleQuotes will surround all strings with single quotes
trimTrailingCommas will omit all trailing commas after the last object entry or array item
// Just concatenate the tokens to produce the same output as was the input.
print(tokens)
// Strip all whitespace. (Just like `JSON.stringify(json)` would do it,
// but leaving comments in the output.)
print(tokens, {})
// Print to multiple lines without object and array indentation.
// (Just introduce line breaks.)
print(tokens, { indent: '' })
// Print to multiple lines with object and array indentation. (Just like
//`JSON.stringify(json, undefined, 2)` would do it, but retaining comments.)
print(tokens, { indent: 2 })
// Print to multiple lines with object and array indentation, omit comments.
// (Just like `JSON.stringify(json, undefined, '  ')` would do it.)
print(tokens, { indent: '  ', pruneComments: true })
// Print to multiple lines with indentation enabled and JSON5 object keys.
print(tokens, { indent: '\t', stripObjectKeys: true })
// Print to multiple lines with indentation enabled, unify JSON5 formatting.
print(tokens, {
  indent: '    ',
  enforceDoubleQuotes: true,
  trimTrailingCommas: true
})

Tokenizing

The method tokenize has the same prototype as the method parse, but returns an array of tokens instead of the JSON object.

const { tokenize } = require('@prantlf/jsonlint')
const tokens = tokenize('{"flag":true /* default */}', {
  ignoreComments: true,
  rawTokens: true
}))
// Returns the following array:
// [
//   { type: 'symbol',     raw: '{',      value: '{' },
//   { type: 'literal',    raw: '"flag"', value: 'flag' },
//   { type: 'symbol',     raw: ':',      value: ':' },
//   { type: 'literal',    raw: 'true',   value: true },
//   { type: 'whitespace', raw: ' ' },
//   { type: 'comment',    raw: '/* default */' },
//   { type: 'symbol',     raw: '}',      value: '}' }
// ]

The tokenize method accepts options in the second optional parameter. See the parse method above for the shared options. There are several additional options supported for the tokenization:

Option Description
rawTokens adds a raw property with the original string from the JSON input
tokenLocations adds a location property with start, end and length of the original string from the JSON input
tokenPaths adds a path property with an array of keys and array indexes "on the way to" the token's value

If you want to retain comments or whitespace for pretty-printing, for example, set rawTokens to true. (The print method requires tokens produced with this flag enabled.)

Performance

This is a part of an output from the parser benchmark, when parsing a 4.68 KB formatted string (package.json) with Node.js 18.14.2:

the standard jsonlint parser x 78,998 ops/sec ±0.48% (95 runs sampled)
the extended jsonlint parser x 7,923 ops/sec ±0.51% (93 runs sampled)
the tokenising jsonlint parser x 6,281 ops/sec ±0.71% (91 runs sampled)

A custom JSON parser is a lot slower than the built-in one. However, it is more important to have a clear error reporting than the highest speed in scenarios like parsing configuration files. (For better error-reporting, the speed can be preserved by using the native parser initially and re-parsing with another parser only in case of failure.) Features like comments or JSON5 are also helpful in configuration files. Tokens preserve the complete input and can be used for pretty-printing without losing the comments.

Error Handling

If parsing fails, a SyntaxError will be thrown with the following properties:

Property Description
message the full multi-line error message
reason one-line explanation of the error
excerpt part of the input string around the error
pointer "--^" pointing to the error in excerpt
location object pointing to the error location

The location object contains properties line, column and offset.

The following code logs twice the following message:

Parse error on line 1, column 14:
{"creative": ?}
-------------^
Unexpected token "?"
const { parse } = require('@prantlf/jsonlint')
try {
  parse('{"creative": ?}')
} catch (error) {
  const { message, reason, excerpt, pointer, location } = error
  const { column, line, offset } = location.start
  // Logs the complete error message:
  console.log(message)
  // Logs the same text as included in the `message` property:
  console.log(`Parse error on line ${line}, ${column} column:
${excerpt}
${pointer}
${reason}`)
}

License

Copyright (C) 2012-2024 Zachary Carter, Ferdinand Prantl

Licensed under the MIT License.

更新日志

Changes

16.0.0 (2024-08-09)

Bug Fixes

  • Use Object.hasOwn instead of Object.prototype.hasOwnProperty (06e7c0f)

BREAKING CHANGES

The minimum supported version of Node.js is 16.9 now.

15.0.0 (2024-08-09)

Features

  • Optionally omit object key proto and others from parsed output (e2f8a7b)

BREAKING CHANGES

Object key __proto__ and other keys from Object.prototype are included in the parsed object by default. Earlier, no keys from Object.prototype were included. The new behaviour is consistent with JSON.parse. If you need the old behaviour, add the argument ignore-prototype-keys to the command line, or set the option ignorePrototypeKeys to true, when calling the parse method. If you don't have under control, what will happens with the parsed object, you should consider setting ignoreProtoKey to true, when calling the parse method, to prevent prototype pollution.

14.1.0 (2024-08-09)

Features

  • Assume --trailing-commas if --trim-trailing-commas is requested (b3fb10d)
  • Add options to sort object keys by locale, numerically and ignoring the letter case (4387c4b)
  • Exit the process with 0 (success) if no files were found and --succeed-with-no-files was requested (923f37f)

Bug Fixes

14.0.3 (2023-04-27)

Bug Fixes

  • Ensure error location by custom parsing (9757213)
  • Upgrade dependencies (30f611a)

14.0.2 (2023-03-08)

Bug Fixes

  • Recognise property "patterns" in the config file again (2619904), closes #18

14.0.1 (2023-03-07)

Bug Fixes

  • Prevent setting a constant variable (c7e940c)

14.0.0 (2023-03-05)

Bug Fixes

  • Replace commander with hand-written command-line parser (af0ea29)

BREAKING CHANGES

  • Although you shouldn't notice any change on the behaviour of the command line, something unexpected might've changed. Something did change: if you're annoyed by inserting "--" between the multi-value option and other arguments, you don't have to do it any more. Multi-value options can be entered either using the option prefix multiple times for each value, or using the option prefix just once and separating the values by commas.

13.1.0 (2023-03-05)

Features

  • Accept multiple schemas if external definitions are used (32d1cab)

13.0.1 (2023-03-05)

Bug Fixes

  • Replace ajv@6 with ajv-draft-04 (b1535a3)

13.0.0 (2023-03-05)

Features

  • Support JSON Schema drafts 2019-09 and 2020-12 and JSON Type Definition (0b9130c)

BREAKING CHANGES

  • The default environment recognises only JSON Schema drafts 06 and 07 automatically. Not 04 any more. The environment for JSON Schema drafts 04 has to be selected explicitly. Also, JSON Schema drafts 06 and 07 are handled by AJV@8 instead of AJV@6. It shouldn't make any difference, but the implementation is new and could perform a stricter validation.

12.0.0 (2023-03-05)

Bug Fixes

  • Upgrade dependencies and require Node.js 14 (87205c2)

BREAKING CHANGES

  • Dropped support for Node.js 12 . The minimum supported version is Node.js 14.

11.7.2 (2023-03-05)

Bug Fixes

  • Use both typings and types in package.json (5d00c00)

11.7.1 (2023-03-05)

Bug Fixes

  • Complete TypeScript types (7064c50)

11.7.0 (2022-09-26)

Bug Fixes

  • Upgrade npm dependencies (81526ce)

Features

  • Ignore the leading UTF-8 byte-order mark (BOM) (311c6df)

11.6.0 (2022-05-04)

Bug Fixes

  • Do not generate text diff if not needed (0423a4b)

Features

  • Allow setting the line count as diff context (9b22843)

11.5.0 (2022-05-03)

Bug Fixes

  • Do not print file names twice in the compact mode (86691cc)

Features

  • Add option "diff" to print the difference instead of the output (cb3826c)

11.4.0 (2022-05-03)

Features

  • Introduce a check that the formatted output is the same as the input (75167f7)

11.3.0 (2022-05-03)

Bug Fixes

  • Fix the regex splitting input by line breaks (7423806)

Features

  • Read options from configuration files (7eebd76)

11.2.0 (2022-05-01)

Features

  • Allow logging only the name of processed files (91346d9)
  • Allow to continue processing in case of error (e5318eb)
  • Support BASH patterns to specify input files (31d162f)

11.1.1 (2022-05-01)

Bug Fixes

  • Retain the original last line break in the processed file (54fd5ab)

11.1.0 (2022-05-01)

Bug Fixes

  • Merge remote-tracking branch 'xmedeko/patch-1' (da3e1dc)

Features

  • Optionally ensure a line break at the end of the output (226019e)

11.0.0 (2022-05-01)

Bug Fixes

BREAKING CHANGES

  • The minimum supported version has become Node.js 12 instead of the previous Node.js 6. At least commander needs the new version.

10.2.0 (2019-12-28)

Features

  • Allow trimming trailing commas in arrays and objects (JSON5) (136ea99)
  • Allow unifying quotes around object keys to double or single ones (JSON5) (6b6da17)

10.1.1 (2019-12-27)

Bug Fixes

  • Restore compatibility with IE11 (55b8a48)

10.1.0 (2019-12-27)

Features

  • Alternatively accept number of spaces for the indent parameter (4c25739)

10.0.2 (2019-12-27)

Bug Fixes

  • Do not modify input options in the tokenize method (7e3ac0b)

10.0.1 (2019-12-27)

Bug Fixes

  • Pretty-printer: keep the comment after opening an object scope indented (4fbc09d)

10.0.0 (2019-12-27)

Bug Fixes

  • Rename the property "exzerpt" in error information to "excerpt" (4c74e3d)

Features

  • Add support for pretty-printing of the JSON input (d5eaa93)

BREAKING CHANGES

  • If you used the property "exzerpt" from the parsing error object, you have to change it to "excerpt". It should be easy using a full-text search in your sources.
  • The option for pretty-printing invalid input has been renamed:

    -p (--pretty-print) ==> -P (--pretty-print-invalid)

The option -p (--pretty-print) will newly prettify the raw (text) input instead of formatting the parsed JSON object.

9.0.0 (2019-12-22)

chore

  • Upgrade package dependencies (4a8f2d9)

Features

BREAKING CHANGES

  • Dependencies (commander, at least) dropped support for Node.js 4. Node.js 6 should still work, but officially it is not supported either. You should upgrade to the current or still supported Node.js LTS version.

8.0.3 (2019-09-24)

Bug Fixes

  • Upgrade package dependencies and adapt sources (9f1f332)

8.0.2 (2019-07-04)

Bug Fixes

  • Put only the reason of the error to the error.reason property when the custom parser is used; not the full message including the error context (8d7f0b1)
  • Update newline replacement regex to show correct error position on Windows (7af364c)

8.0.0 (2019-06-16)

Bug Fixes

  • Give the schema-drafts.js proper name and path in source maps (c2f0148)

Features

  • Add the tokenize method returning tokens instead of the parsed object (cc7b554)
  • Improve schema error reporting to the level of data parsing (ea5a8a2)
  • Remove deprecated exports Parser and parser (8bda5b1)

BREAKING CHANGES

  • The Parser class and parser instance did not bring any benefit. They were generated by Jison. After abandoning the Jison parser they were kept for compatibility only. The only method on the Parser prototype was the parse. It remains unchanged as a direct export. Drop the class interface and just call the parse method directly.

7.0.3 (2019-06-03)

Bug Fixes

  • Ensure, that tokens and keys in error messages are enclosed in quotation marks (2149198)

7.0.2 (2019-06-02)

Bug Fixes

  • Upgrade minificating module (04d80d7)

7.0.1 (2019-06-02)

Bug Fixes

  • Recognize boxed string as schema environment too (e37b004)

7.0.0 (2019-06-02)

Bug Fixes

  • Do not use the native parser in Safari and Node.js 4 (a4a606c)
  • Include the minified scripts used on the on-line page in the NPM module (03561ec)

Features

  • Add "mode" parameter to set flags for a typical format type easier (9aa09fb)
  • Add an option for ignoring trailing commas in object and arrays (7d521fb)
  • Add an option for reporting duplicate object keys as an error (09e3977)
  • Replace the parser generated by Jison with a hand-built parser from JJU (2781670)
  • Support reviver from the native JSON.parse method (83cd33c)

BREAKING CHANGES

  • There is no yy.parseError to intercept error handling. Use the thrown error - it contains all available information. The error does not include the hash object with structured information. Look for the documentd properties. The location of the error occurrence is available as location.start, for example.

DEPRECATION: The only exposed object to use from now on is the parse method as a named export. Other exports (parser and Parser) are deprecated and will be removed in future.

The parser from "Utilities to work with JSON/JSON5 documents" is four times faster, than the previous one, has approximatly the same size and can be easier enhanced, regarding both features and error handling.

6.3.1 (2019-05-31)

Bug Fixes

  • Recognise the location of error occurrences in Firefox (7c8c040)

6.3.0 (2019-05-30)

Bug Fixes

  • Auto-detect the version of the JSON Schema draft by default (1fe98ef)
  • Prefer the native JSON parser, if possible, to improve performance (1639356)

Features

  • Support parser options for customisation and performance in JSON schema parsing too (d562826)

6.2.1 (2019-05-30)

Bug Fixes

  • Include source code in source maps on the on-line validator page (31e0097)

6.2.0 (2019-05-30)

Features

  • Extract the functionality for sorting object keys to a module (a53bd93)

6.1.0 (2019-05-27)

Bug Fixes

  • Fix the missing function object (Parser) in the main module exports (eb892aa)
  • Restore context options (yy) set in the Parser constructor after the call to parse, if the options were overridden by the method arguments (787c350)

Features

  • Use the native JSON parser if a limited error information is enough (8aa9fb1)

6.0.0 (2019-05-26)

Features

  • Declare modules in this package using UMD (d442583)
  • Remove ParserWithComments and parseWithComment from the interface (3fab374)

BREAKING CHANGES

  • The object and the method do not exist any more. Pass the parameter "ignoreComments" as an object { ignoreComments: true } either to the constructor of the Parser object, or as the second parameter to the method parse.

5.0.0 (2019-05-26)

Bug Fixes

  • Do not export "main" method, which requires other NPM modules (d8af36a)

Features

  • Accept single quotes (apostrophes) as string delimiters (240b8cd)

BREAKING CHANGES

  • The "main" method providing a command-line interface importable from other module has been removed. If you used it, have a look at the command-line interface in lib/cli. You can import this module in instead and it offers a richer interface, than the previously exported "main" method. The lib/cli module is mapped to bin/jsonlint too. However, consider the default library export (lib/jsonlint) for programmatic usage. You will pack less JavaScript code and use smalker, mode programmer-oriented interface.

4.0.2 (2019-05-19)

Bug Fixes

  • Print parsing errors if the JSON input is read from stdin (acfdf11)

4.0.1 (2019-05-19)

Bug Fixes

  • Do not fail sorting objects with a property called "hasOwnProperty" (b544ceb)

4.0.0 (2019-05-19)

Bug Fixes

  • Standardize the interface of the "jsonlint/lib/formatter" module (b8b041b)

Features

  • Add web and programmatic interfaces to JSON Schema validation (d45b243)

BREAKING CHANGES

  • The formatting method is exposed not as exports.formatter.formatJson, but as exports.format. This module is not documented and it is unlikely, that it broke other project.

3.0.0 (2019-05-18)

Bug Fixes

  • Replace JSON schema validator JSV with ajv, because JSV is not maintained any more and does not support current JSON schema drafts (1a4864f)

BREAKING CHANGES

  • The environment for the JSON schema validation "json-schema-draft-03" is not available any more. Migrate your schemas from the JSON schema draft 03 to 04 or newer. Drafts 04, 06 and 07 are supported with this release.

2.0.1 (2019-05-18)

Bug Fixes

  • Do not depend on the standard checker in the release package (1e9c7b5)

2.0.0 (2019-05-18)

Bug Fixes

  • Accept any file extension on the command line directly (14ba31c)
  • Do not distribute the web directory in the npm module (7379be8)
  • Make the compact-errors mode working with the latest Jison output (d417a9c)
  • Rename the long name of the option "extension" to "extensions" (383e50a)
  • Replace nomnom as command-line parser with commander, which is maintaitained (6694bba)
  • Report the right file name in the compact-errors mode, if multiple files or directories are engtered (7c80326)

Features

  • Add a checkbox to recognize JavaScript-style comments to the web page (2a9082a)
  • Support parsing and skipping JavaScript-style comments in the JSON input (4955c58)

BREAKING CHANGES

  • The options "extension" is not recognized any more. Use the option "extensions" with the same semantics instead.

1.7.0 (2019-05-18)

Features

  • Allow specifying JSON file extensions for directory walk (d8e8076)

This is the first version released after forking the original project.