json_patch 3.0.0 copy "json_patch: ^3.0.0" to clipboard
json_patch: ^3.0.0 copied to clipboard

Pure Dart utility package for the JSON Patch standard. Can apply patch operations as well as perform a diff algorithm on JSON-like objects.

example/main.dart

import 'package:json_patch/json_patch.dart';

void main() {
  final diff = JsonPatch.diff(
    {
      'test': 5,
      'object': {
        'list': [1, 2, 3],
        'child': 'value',
      }
    },
    {
      'test': 6,
      'object': {
        'list': [1, 2, 4],
        'child': 5,
      }
    },
  );
  print('Diff algorithm found changes: $diff');

  try {
    final newJson = JsonPatch.apply(
      {
        'a': 5,
      },
      [
        {'op': 'test', 'path': '/a', 'value': 5},
        {
          'op': 'add',
          'path': '/test',
          'value': {'child': 'value'}
        },
        {'op': 'move', 'from': '/test', 'to': '/moved'},
      ],
      strict: true,
    );
    print('Object after applying patch operations: $newJson');
  } on JsonPatchTestFailedException catch (e) {
    print(e);
  }
}
22
likes
140
pub points
88%
popularity

Publisher

verified publisherjulien-scholz.dev

Pure Dart utility package for the JSON Patch standard. Can apply patch operations as well as perform a diff algorithm on JSON-like objects.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

collection

More

Packages that depend on json_patch