json_patch 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 74

JSON Patch for Dart #

A simple utility package for JSON Patch. Includes a simple diff algorithm as well as the ability to apply JSON Patch operations to a JSON-like Dart object.

Usage #

import 'package:json_patch/json_patch.dart';

...

final ops = JsonPatch.diff(oldJson, newJson);
try {
    final patchedJson = JsonPatch.apply(json, patches, strict: false);
} on JsonPatchTestFailedException catch (e) {
    print(e);
}

See the example or the API docs for more information.

1.0.2 #

  • Loosen dependency version constraints
  • Improve README.md and example

1.0.1 #

  • Apply maintenance and health suggestions

1.0.0 #

  • Initial release

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);
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  json_patch: ^1.0.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:json_patch/json_patch.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
48
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
74
Learn more about scoring.

We analyzed this package on Dec 4, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:json_patch/json_patch.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
collection >=1.0.0 <2.0.0 1.14.12
Dev dependencies
test any