搜索插件、代码仓与 APP 分类

插件详情v0.2.1

json_diff

用于比较两个 JSON 对象的工具

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1.4万
喜欢数
25
Pub 分数
130

安装插件

flutter pub add json_diff

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter/Dart 包,提供比较两个 JSON 对象并生成详细差异的实用工具。它能识别结构之间的新增、删除和修改,非常适合跟踪 JSON 数据的变化。该包支持嵌套对象和数组,提供清晰、结构化的输出,帮助开发者以编程方式理解差异。专为跨平台使用设计,可在 Android、iOS、Web、macOS、Windows 和 Linux 上无缝运行。该库轻量且易于集成到现有的 Dart 项目中。

适合场景

  • 比较 API 响应
  • 跟踪配置更改
  • 调试 JSON 更新
  • 版本化 JSON 数据
  • 实时数据同步
  • 验证数据完整性

主要特点

  • 嵌套对象比较
  • 数组差异检测
  • 清除差异输出格式
  • 跨平台兼容性
  • 轻量且快速
  • 支持 null 和基本类型值

适合对象

  • 使用动态 JSON 的开发者
  • 需要更改跟踪的应用程序
  • 数据验证工具
  • 调试和测试工作流程
  • 实时协作功能

使用建议

  • 可能无法处理循环引用
  • 大型 JSON 可能会影响性能
  • 输出格式需要解析
  • diff逻辑的自定义有限
  • 不适用于二进制数据
  • 需要手动处理复杂类型

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Build Status

Generate a diff between two JSON strings.

Usage

Here's a basic example which features a deleted object, a new object, a changed object, and a deeply changed object:

import 'package:json_diff/json_diff.dart';

final left = {"a": 2, "b": 3, "c": 5, "d": {"x": 4, "y": 8}};
final right = {"b": 7, "c": 5, "d": {"x": 4, "z": 16}, "e": 11};
final differ = JsonDiffer.fromJson(left, right);
DiffNode diff = differ.diff();
print(diff.added);              // => {"e": 11}
print(diff.removed);            // => {"a": 2}
print(diff.changed);            // => {"b": [3, 7]}
print(diff.node);               // => a Map<String,DiffNode>
print(diff.node['d']);          // => a DiffNode
print(diff.node['d'].added);    // => {"z": 16}
print(diff.node['d'].removed);  // => {"y": 8}

So that's pretty fun. So when you diff two JSON strings, you get back a DiffNode. A DiffNode is a heirarchical structure that vaguely mirrors the structure of the input JSON strings. In this example, the top-level DiffNode we got back has

  • an added property, which is a Map of top-level properties that were not found in left, and were found in right.
  • a removed property, which is a Map of top-level properties that were found in left, but were not found in right.
  • a changed property, which is a Map of top-level properties whose values are different in left and in right. The values in this Map are two-element Arrays. The 0th element is the old value (from left), and the 1st element is the new value (from right).
  • a moved property, which is a Map of indexes, where key is the original index of an element, and value is index in the changed list.
  • a node property, a Map of the properties found in both left and right that have deep differences. The values of this Map are more DiffNodes.
  • a path property, which is a List of indexes, describing the path from the root where this DiffNode is operating.

Contributing

Contributions welcome! Please read the contribution guidelines.

Disclaimer

This is not an official Google product.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。