# json0-ot-diff

> Finds differences between two JSON object and generates operational transformation (OT) operations for transforming the first object into the second.

Latest version **1.1.2** (published 2021-12-17) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install json0-ot-diff
pnpm add json0-ot-diff
yarn add json0-ot-diff
bun add json0-ot-diff
```

## 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.1.2 |
| Published | 2021-12-17 |
| First published | 2016-06-30 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 24.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 131 |
| Author | Kristian Antonsen |
| Maintainers | kbadk |
| Keywords | json, json0, ot, operational, transformation, diff |

## Links

- npm: https://www.npmjs.com/package/json0-ot-diff
- Repository: https://github.com/kbadk/json0-ot-diff
- Homepage: https://github.com/kbadk/json0-ot-diff#readme
- Issues: https://github.com/kbadk/json0-ot-diff/issues
- npm.io page: https://npm.io/package/json0-ot-diff

## Dependencies (1)

- [deep-equal](https://npm.io/package/deep-equal.md) ^1.0.1

## 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.1.2 (latest) — 2021-12-17
- 1.1.1 — 2021-12-13
- 1.1.0 — 2021-11-19
- 1.0.8 — 2021-07-08
- 1.0.7 — 2021-06-08
- 1.0.6 — 2021-05-10
- 1.0.5 — 2019-07-31
- 1.0.4 — 2019-06-14
- 1.0.3 — 2018-04-04
- 1.0.2 — 2017-12-03
- 1.0.1 — 2016-07-01
- 1.0.0 — 2016-06-30

## README

# JSON0 OT Diff

Finds differences between two JSON object and generates operational transformation (OT) operations for transforming the first object into the second according to the [JSON0 OT Type](https://github.com/ottypes/json0).

The current implementation supports list/object insertion/deletion (i.e. `li`, `ld`, `oi`, `od`) out of the box.

	var jsondiff = require("./json0-ot-diff");

	var diff = jsondiff(
		["foo", "bar", 1, 2, 3],
		["foo", "quux", 1, 2]
	);
	console.log(diff);

	> [
	>	{ p: [ 1 ], ld: 'bar', li: 'quux' },
	>	{ p: [ 4 ], ld: 3 }
	>]

String insertion/deletion (i.e. `si`, `sd`) operations are generated for string mutations if you provide a reference to [diff-match-patch](https://github.com/google/diff-match-patch).

	var diffMatchPatch = require("diff-match-patch");
	var diff = jsondiff(
		["foo", "The only change here is at the end.", 1, 2, 3],
		["foo", "The only change here is at the very end.", 1, 2],
		diffMatchPatch
	);
	console.log(diff);

	> [
	> { p: [ 1, 31 ], si: 'very ' },
	> { p: [ 4 ], ld: 3 }
	>]

The [JSON1 OT Type](https://github.com/ottypes/json1) is supported as well. To generate ops for the JSON1 OT type, provide a reference to [diff-match-patch](https://github.com/google/diff-match-patch), [ot-json1](https://github.com/ottypes/json1) and [ot-text-unicode](https://github.com/ottypes/text-unicode).

	var diffMatchPatch = require("diff-match-patch");
	var json1 = require("ot-json1");
	var textUnicode = require("ot-text-unicode");
	var diff = jsondiff(
		["foo", "The only change here is at the end.", 1, 2, 3],
		["foo", "The only change here is at the very end.", 1, 2],
		diffMatchPatch,
		json1,
		textUnicode
	);
	console.log(diff);

	>[
	>  [ 1, { "es": [ 31, "very " ] } ],
	>  [ 4, { "r": true } ]
	>]

This was developed for [JsonML](http://www.jsonml.org/) with [Webstrates](https://github.com/cklokmose/Webstrates) in mind, but could be applicable in other situations.

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