# codemirror-json5

> JSON5 support for Codemirror 6

Latest version **1.0.3** (published 2023-06-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install codemirror-json5
pnpm add codemirror-json5
yarn add codemirror-json5
bun add codemirror-json5
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2023-06-28 |
| First published | 2022-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 7 |
| Unpacked size | 26.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Daniel Imfeld |
| Maintainers | dimfeld |
| Keywords | Codemirror, editor, code, json5 |

## Links

- npm: https://www.npmjs.com/package/codemirror-json5
- Repository: https://github.com/dimfeld/codemirror-json5
- Homepage: https://github.com/dimfeld/codemirror-json5#readme
- Issues: https://github.com/dimfeld/codemirror-json5/issues
- npm.io page: https://npm.io/package/codemirror-json5

## Dependencies (7)

- [json5](https://npm.io/package/json5.md) ^2.2.1
- [lezer-json5](https://npm.io/package/lezer-json5.md) ^2.0.2
- [@lezer/common](https://npm.io/package/@lezer/common.md) ^1.0.0
- [@codemirror/view](https://npm.io/package/@codemirror/view.md) ^6.0.0
- [@lezer/highlight](https://npm.io/package/@lezer/highlight.md) ^1.0.0
- [@codemirror/state](https://npm.io/package/@codemirror/state.md) ^6.0.0
- [@codemirror/language](https://npm.io/package/@codemirror/language.md) ^6.0.0

## 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.3 (latest) — 2023-06-28
- 1.0.2 — 2023-06-11
- 1.0.1 — 2023-06-10
- 1.0.0 — 2022-12-10

## README

# codemirror-json5

This package implements JSON5 support for Codemirror 6.

Beyond the basic support, it provides a linter and state fields that expose:

- The parsed object produced by the JSON5 parser, so that your surrounding code can use that result instead of parsing it twice.
- The path in the object that the cursor is on.

## Usage

```javascript
import { json5, json5ParseLinter } from 'codemirror-json5';
import { linter } from '@codemirror/lint';
import { EditorState } from '@codemirror/state';
import { EditorView } from '@codemirror/view';

const view = new EditorView({
  state: EditorState.create({
    doc: `{ a_doc: 'goes here' }`,
    extensions: [
      json5(),
      linter(json5ParseLinter()),
    ]
  })
});
```

## Retrieving Editor State

```typescript
import { EditorState } from '@codemirror/state';
import { jsonCursorPath, json5ParseCache } from 'codemirror-json5';
import get from 'just-safe-get';

function getJson5Info(state: EditorState) {
  const object = state.field(json5ParseCache);
  const { path } = state.field(jsonCursorPath);

  return {
    parsed: object.obj,
    parseError: object.err,
    cursorPath: path,
    cursorValue: get(object.obj ?? {}, path),
  };
}
```

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