搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。