jdiff 1.0.0
jdiff: ^1.0.0 copied to clipboard
A pure Dart implementation of RFC 6902 JSON Patch and RFC 6901 JSON Pointer. Provides diff, patch, and apply operations for JSON-like Dart objects. Ideal for sync apps, offline-first architectures, an [...]
Changelog #
All notable changes to jdiff will be documented in this file.
The format follows Keep a Changelog, and this project adheres to Semantic Versioning.
1.0.0 — 2026-05-29 #
Added #
Core
JsonPatch— high-level static API withdiff,apply,applyJson,patch,toJsonList,fromJsonList, and six convenience single-operation helpers (add,remove,replace,move,copy,test).JsonPointer— complete RFC 6901 implementation:parse()factory with full~0/~1escape / unescape support.fromTokens()androotconstant.get,exists,set,insert,removenavigation methods (all immutable — original document is never mutated).parent,child,isDescendantOfpointer-arithmetic helpers.- Round-trip
toString()serialisation with correct escaping order.
- All six RFC 6902 operations as const-constructable sealed subclasses:
AddOperation,RemoveOperation,ReplaceOperation,MoveOperation,CopyOperation,TestOperation. PatchOperation.fromJson/toJsonfor wire serialisation.PatchApplierengine:- Atomic application — exceptions bubble up without partial state.
- Deep copy on
copyoperations to prevent shared references. - Deep equality for
testoperations. JsonPatchConflictExceptionfor illegalmove(path is a descendant offrom).
PatchDifferengine:- Object diff: key-by-key
add/remove/ recursive descent. - Array diff: element-wise
replacefor common prefix,add /-for extra target elements, back-to-frontremovefor extra source elements. - Handles both typed (
Map<String, dynamic>) and untyped ({}literal) Dart maps transparently.
- Object diff: key-by-key
Exceptions
JsonPointerException— pointer syntax / navigation errors.JsonPatchException— general patch-application failure with optionaloperationandpathcontext.JsonPatchTestFailedException—testassertion failure, carryingexpectedandactualvalues.JsonPatchConflictException—moveconflict (RFC 6902 §4.4).
Tests — 216 tests across 5 suites
exceptions_test.dart— all four exception classes (19 tests).json_pointer_test.dart— full RFC 6901 coverage (56 tests).patch_applier_test.dart— all six operations + atomicity + helpers (47 tests).patch_differ_test.dart— no-ops, map diffs, array diffs, type changes, round-trip correctness, serialisation (37 tests).rfc6902_compliance_test.dart— all 17 RFC Appendix A cases + extended community edge-case suite (29 tests).
Documentation
- Comprehensive
README.mdwith Quick Start, full API reference, use-cases (offline-first, real-time, optimistic locking, HTTP PATCH), and bandwidth savings analysis. - Fully documented
example/jdiff_example.dartwith 6 real-world scenarios. - Dartdoc comments on every public symbol.
Technical Notes #
- Requires Dart SDK
>=3.0.0 <4.0.0— uses sealed classes, pattern matching,abstract final class, andconstconstructors throughout. - Zero runtime dependencies —
dev_dependenciesonly (test,lints). - Strict static analysis via
package:lints/recommended.yamlwithstrict-casts,strict-inference, andstrict-raw-typesenabled.