# json-parse-context

> Add the context of a json parse error to the error message with syntax highlighting if possible.

Latest version **1.0.1** (published 2020-08-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install json-parse-context
pnpm add json-parse-context
yarn add json-parse-context
bun add json-parse-context
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2020-08-21 |
| First published | 2020-08-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 34.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Nick Oliver |
| Maintainers | amexopensource |
| Keywords | json, parse, terminal, friendly, syntax, highlighting |

## Links

- npm: https://www.npmjs.com/package/json-parse-context
- Repository: https://github.com/americanexpress/json-parse-context
- Homepage: https://github.com/americanexpress/json-parse-context#readme
- Issues: https://github.com/americanexpress/json-parse-context/issues
- npm.io page: https://npm.io/package/json-parse-context

## Dependencies (2)

- [cardinal](https://npm.io/package/cardinal.md) ^2.1.1
- [ansicolors](https://npm.io/package/ansicolors.md) ^0.3.2

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.1 (latest) — 2020-08-21

## README

<h1 align="center">
  <img src="https://github.com/americanexpress/json-parse-context/raw/main/json-parse-context.png" alt="json-parse-context - One Amex" width='50%'/>
</h1>

> Add the context of a json parse error to the error message with syntax highlighting if possible.

[![npm](https://img.shields.io/npm/v/json-parse-context)](https://www.npmjs.com/package/json-parse-context)
![Main Health Check](https://github.com/americanexpress/json-parse-context/workflows/Main%20Health%20Check/badge.svg)

## 📖 Table of Contents

* [Features](#-features)
* [API](#%EF%B8%8F-api)
* [Available Scripts](#-available-scripts)
* [Git Hooks](#-git-hooks)
* [Contributing](#-contributing)

<br />

## ✨ Features

### Example:

```javascript
const jsonParseContext = require('json-parse-context');

jsonParseContext(`{
  "going": "to"
  "fail" true
}`);
```

![terminal screenshot showing the line with a JSON syntax error surrounded by the previous and following lines](./context-example.png)

<br />

## 🎛️ API

`jsonParseContext(serialized [, reviver [, options]])`
* `serialized` (`String`): [serialized JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters)
* `reviver` (`Function`): [prescribes how the value originally produced by parsing is transformed](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters)
* `options` (`Object`)
  * `lineCount` (`Number`) [_default: `2`_]: lines of context to add above and below the line with a syntax error

<br />

## 📜 Available Scripts

In the project directory, you can run:

**`npm run test:git-history`**

Validates commit messages using [`commitlint`](https://commitlint.js.org/)

**`npm run test:lint`**

Verifies that your code matches the American Express code style defined in [`eslint-config-amex`](https://github.com/americanexpress/eslint-config-amex).

**`npm run test:lockfile`**

Validates `package-lock.json` with [`lockfile-lint](https://www.npmjs.com/package/lockfile-lint)

**`npm run test:unit`**

Runs the unit tests using [`jest`](https://jestjs.io/) with the presets defined in
[`amex-jest-preset`](https://github.com/americanexpress/amex-jest-preset).

**`npm test`**

Runs all of the above `test:*` commands

<br />

## 🎣 Git Hooks

These commands will be automatically run during normal git operations like committing code.

**`pre-commit`**

This hook runs `npm test` before allowing a commit to be checked in.

**`commit-msg`**

This hook verifies that your commit message matches the One Amex conventions. See the **commit
message** section in the [contribution guidelines](./CONTRIBUTING.md).
 
 <br />

## 🏆 Contributing

See [contributing guidelines](./CONTRIBUTING.md)

<br />

## 🗝️ License

Any contributions made under this project will be governed by the [Apache License 2.0](https://github.com/americanexpress/json-parse-context/blob/main/LICENSE.txt).

<br />

## 🗣️ Code of Conduct

This project adheres to the [American Express Community Guidelines](https://github.com/americanexpress/json-parse-context/blob/main/CODE_OF_CONDUCT.md).
By participating, you are expected to honor these guidelines.

---
_Source: https://npm.io/package/json-parse-context · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
