Skip to content

AmanGIT07/go-json-diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Diff Tool

A custom JSON diff implementation that keeps array changes intact.

Files

  • diff_calculator.go - Calculates differences between two JSON objects
  • diff_reconstructor.go - Reconstructs original JSON from current JSON + diff
  • demo.go - Demonstrates both operations

Usage

Run all three files together:

go run diff_calculator.go diff_reconstructor.go demo.go

Operations

Generate Diff

differ := NewJSONDiffer()
diffs, err := differ.Compare(json1, json2)

Reconstruct Original

reconstructor := NewJSONReconstructor()
original, err := reconstructor.ReverseDiff(currentJSON, diffs)

Diff Format

{
  "field_name": "arr",
  "change_type": "modified",
  "from_value": "[1,2,3]",
  "to_value": "[1,3,4]", 
  "full_path": "/fruits/arr",
  "value_type": "array"
}

Change Types

  • added - New field
  • removed - Deleted field
  • modified - Changed field

Array Handling

Arrays are treated as complete units. Changes like [1,2,3][1,3,4] create a single modification entry, not element-by-element diffs.

Dependencies

Uses only Go standard library:

  • encoding/json
  • fmt
  • reflect
  • sort
  • strconv
  • strings

About

calculates difference between two json

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages