# parse-conflict-json

> Parse a JSON string that has git merge conflicts, resolving if possible

Latest version **6.0.0** (published 2026-05-15) · ISC license · 0 weekly downloads

## Install

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

## Health

**Score 63/100 (C)** — status: active.

Positive: has types package; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 6.0.0 |
| Published | 2026-05-15 |
| First published | 2019-08-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/parse-conflict-json) |
| Module format | CommonJS |
| Node | ^22.22.2 \|\| ^24.15.0 \|\| >=26.0.0 |
| Dependencies | 3 |
| Unpacked size | 6.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 36 |
| Author | GitHub Inc. |
| Maintainers | saquibkhan, npm-cli-ops, reggi, owlstronaut |

## Links

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

## Dependencies (3)

- [just-diff](https://npm.io/package/just-diff.md) ^6.0.0
- [just-diff-apply](https://npm.io/package/just-diff-apply.md) ^5.2.0
- [json-parse-even-better-errors](https://npm.io/package/json-parse-even-better-errors.md) ^6.0.0

## Recent versions

- 6.0.0 (latest) — 2026-05-15
- 5.0.1 — 2025-10-23
- 5.0.0 — 2025-10-22
- 4.0.0 — 2024-09-25
- 3.0.1 — 2023-03-21
- 3.0.0 — 2022-10-14
- 2.0.2 — 2022-03-28
- 2.0.1 — 2021-12-08
- 2.0.0 — 2021-12-08
- 1.1.1 — 2020-08-20
- 1.1.0 — 2020-07-14
- 1.0.1 — 2019-08-09
- 1.0.0 — 2019-08-07

## README

# parse-conflict-json

Parse a JSON string that has git merge conflicts, resolving if possible.

If the JSON is valid, it just does `JSON.parse` as normal.

If either side of the conflict is invalid JSON, then an error is thrown for
that.

## USAGE

```js
// after a git merge that left some conflicts there
const data = fs.readFileSync('package-lock.json', 'utf8')

// reviverFunction is passed to JSON.parse as the reviver function
// preference defaults to 'ours', set to 'theirs' to prefer the other
// side's changes.
const parsed = parseConflictJson(data, reviverFunction, preference)

// returns true if the data looks like a conflicted diff file
parsed.isDiff(data)
```

## Algorithm

If `prefer` is set to `theirs`, then the vaules of `theirs` and `ours` are
switched in the resolver function.  (Ie, we'll apply their changes on top
of our object, rather than the other way around.)

- Parse the conflicted file into 3 pieces: `ours`, `theirs`, and `parent`

- Get the [diff](https://github.com/angus-c/just#just-diff) from `parent`
  to `ours`.

- [Apply](https://github.com/angus-c/just#just-diff-apply) each change of
  that diff to `theirs`.

    If any change in the diff set cannot be applied (ie, because they
    changed an object into a non-object and we changed a field on that
    object), then replace the object at the specified path with the object
    at the path in `ours`.

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