parse-json

WebJar for parse-json

Лицензия

Лицензия

MIT
Категории

Категории

JSON Данные
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

parse-json
Последняя версия

Последняя версия

5.2.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

parse-json
WebJar for parse-json
Ссылка на сайт

Ссылка на сайт

https://www.webjars.org
Система контроля версий

Система контроля версий

https://github.com/sindresorhus/parse-json

Скачать parse-json

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/parse-json/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>parse-json</artifactId>
    <version>5.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/parse-json/
implementation 'org.webjars.npm:parse-json:5.2.0'
// https://jarcasting.com/artifacts/org.webjars.npm/parse-json/
implementation ("org.webjars.npm:parse-json:5.2.0")
'org.webjars.npm:parse-json:jar:5.2.0'
<dependency org="org.webjars.npm" name="parse-json" rev="5.2.0">
  <artifact name="parse-json" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='parse-json', version='5.2.0')
)
libraryDependencies += "org.webjars.npm" % "parse-json" % "5.2.0"
[org.webjars.npm/parse-json "5.2.0"]

Зависимости

compile (4)

Идентификатор библиотеки Тип Версия
org.webjars.npm : babel__code-frame jar [7.0.0,8)
org.webjars.npm : error-ex jar [1.3.1,2)
org.webjars.npm : json-parse-even-better-errors jar [2.3.0,3)
org.webjars.npm : lines-and-columns jar [1.1.6,2)

Модули Проекта

Данный проект не имеет модулей.

parse-json

Parse JSON with more helpful errors

Install

$ npm install parse-json

Usage

const parseJson = require('parse-json');

const json = '{\n\t"foo": true,\n}';


JSON.parse(json);
/*
undefined:3
}
^
SyntaxError: Unexpected token }
*/


parseJson(json);
/*
JSONError: Unexpected token } in JSON at position 16 while parsing near '{      "foo": true,}'

  1 | {
  2 |   "foo": true,
> 3 | }
    | ^
*/


parseJson(json, 'foo.json');
/*
JSONError: Unexpected token } in JSON at position 16 while parsing near '{      "foo": true,}' in foo.json

  1 | {
  2 |   "foo": true,
> 3 | }
    | ^
*/


// You can also add the filename at a later point
try {
	parseJson(json);
} catch (error) {
	if (error instanceof parseJson.JSONError) {
		error.fileName = 'foo.json';
	}

	throw error;
}
/*
JSONError: Unexpected token } in JSON at position 16 while parsing near '{      "foo": true,}' in foo.json

  1 | {
  2 |   "foo": true,
> 3 | }
    | ^
*/

API

parseJson(string, reviver?, filename?)

Throws a JSONError when there is a parsing error.

string

Type: string

reviver

Type: Function

Prescribes how the value originally produced by parsing is transformed, before being returned. See JSON.parse docs for more.

filename

Type: string

Filename displayed in the error message.

parseJson.JSONError

Exposed for instanceof checking.

fileName

Type: string

The filename displayed in the error message.

codeFrame

Type: string

The printable section of the JSON which produces the error.


Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.

Версии библиотеки

Версия
5.2.0
5.1.0
5.0.1
5.0.0
4.0.0
3.0.0
2.2.0