Documentation ¶
Overview ¶
jsondiff is a zero-dependencies simple JSON differ.
Example ¶
package main import ( "fmt" "github.com/andreyvit/jsondiff" ) func main() { before := map[string]any{ "foo": 10, "bar": 20, "boz": 30, } after := map[string]any{ "foo": 10, "bar": 42, } diff := jsondiff.CompareObjects(before, after) fmt.Println(diff.Format(before)) }
Output: { - "bar": 20, + "bar": 42, - "boz": 30, "foo": 10 }
Index ¶
Examples ¶
Constants ¶
View Source
const ( AsciiSame = " " AsciiAdded = "+" AsciiDeleted = "-" )
Variables ¶
View Source
var AsciiStyles = map[string]string{ AsciiAdded: "30;42", AsciiDeleted: "30;41", }
Functions ¶
This section is empty.
Types ¶
type Delta ¶
type Delta interface { // Similarity ranges from 0 (completely different) to 1 (completely equal). Similarity() float64 PositionMatches(pos Position) bool }
A Delta represents an atomic difference between two JSON objects.
type FormatOption ¶
type FormatOption int
FormatOption can be passed to Diff.Format. Treat these as opaque, i.e. don't rely on the underlying type or values of FormatOptions.
const ( ShowArrayIndex FormatOption = iota Colored HideUnchangedProperties )
type Index ¶
type Index int
A Index is a Position with an int value, which means the Delta is in an Array.
type Modified ¶
type Modified struct { Position Position OldValue any NewValue any // contains filtered or unexported fields }
A Modified represents a field whose value is changed.
func NewModified ¶
func (*Modified) PositionMatches ¶
func (*Modified) Similarity ¶
type Moved ¶
type Moved struct { OldPosition Position NewPosition Position Value any // contains filtered or unexported fields }
func (*Moved) PositionMatches ¶
func (*Moved) Similarity ¶
type Name ¶
type Name string
A Name is a Postition with a string, which means the delta is in an object.
type Position ¶
type Position interface { // String returns the position as a string String() (name string) Equal(another Position) bool // CompareTo returns a true if the Position is smaller than another Position. // This function is used to sort Positions by the sort package. CompareTo(another Position) bool }
A Position represents the position of a Delta in an object or an array.
Click to show internal directories.
Click to hide internal directories.