두 개의 JSON 객체를 비교하고 상세한 차이점을 생성하는 유틸리티를 제공하는 플러터/다트 패키지입니다. 구조 간에 추가, 삭제, 수정을 식별하여 JSON 데이터의 변경 사항을 추적하는 데 이상적입니다. 중첩된 객체와 배열을 지원하며, 개발자가 프로그래밍적으로 차이점을 이해할 수 있도록 명확하고 구조화된 출력을 제공합니다. 크로스플랫폼 사용을 위해 설계되어 안드로이드, iOS, 웹, 맥OS, 윈도우, 리눅스에서 원활하게 작동합니다. 라이브러리는 가볍고 기존의 다트 프로젝트에 쉽게 통합할 수 있습니다.
사용 사례
API 응답 비교
구성 변경 추적
JSON 업데이트 디버깅
버전 관리된 JSON 데이터
실시간 데이터 동기화
데이터 무결성 검증
주요 기능
중첩된 객체 비교
배열 차이 감지
차이 출력 형식 지우기
크로스 플랫폼 호환성
경량이고 빠름
null 및 기본값을 지원합니다
적합한 대상
동적 JSON을 사용하는 개발자
변경 추적을 필요로 하는 앱
데이터 검증 도구
디버깅 및 테스트 워크플로우
실시간 협업 기능
고려 사항
순환 참조를 처리하지 못할 수 있습니다
큰 JSON은 성능에 영향을 줄 수 있습니다
출력 형식은 구문 분석이 필요합니다
diff 로직의 사용자 정의 제한
이진 데이터용으로 설계되지 않음
복잡한 형식에 대한 수동 처리가 필요합니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
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 DiffNodeprint(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.