Compare Go Slices Online
Paste two Go slices (as JSON arrays). See what was added, removed, or changed — element by element.
🔒 100% private — runs entirely in your browseror try sample data
Paste two Go slices (as JSON arrays). See what was added, removed, or changed — element by element.
🔒 100% private — runs entirely in your browseror try sample data
Go Slice Diff compares two Go slices element by element and shows exactly what changed. Go intentionally does not support == comparison for slices — you get a compile error if you try. This tool gives you instant visual comparison without writing boilerplate code.
Go slices are dynamically-sized, typed views into arrays. They are the primary collection type in Go and are used everywhere: function parameters, API responses (via json.Marshal), database results, and configuration. Comparing slices is a common need during debugging and testing.
Serialize your slices to JSON with json.Marshal() and paste the output here. The tool handles nested slices, struct fields, maps, and mixed types. Everything runs locally in your browser.
package main import ( "fmt" "reflect"
) func main() { a := []string{"gin", "echo", "fiber"} b := []string{"gin", "echo", "chi"} fmt.Println(reflect.DeepEqual(a, b)) // false
}DeepEqual tells you whether slices differ but not what changed or where.
package main import ( "fmt" "slices"
) func main() { a := []int{1, 2, 3, 4} b := []int{1, 2, 3, 5} fmt.Println(slices.Equal(a, b)) // false
}slices.Equal is type-safe and efficient but only returns a boolean — no diff detail.
func diffSlices(a, b []string) { maxLen := len(a) if len(b) > maxLen { maxLen = len(b) } for i := 0; i < maxLen; i++ { va, vb := "(missing)", "(missing)" if i < len(a) { va = a[i] } if i < len(b) { vb = b[i] } if va != vb { fmt.Printf("[%d]: %s -> %s\n", i, va, vb) } }
}Works for flat slices but cannot handle nested structs or maps.
Go does not allow == on slices (compile error). The only built-in comparison is == nil. For value comparison, use reflect.DeepEqual, slices.Equal (Go 1.21+), or serialize to JSON and compare strings.
var s []int (nil) and s := []int{} (empty) behave the same for most operations but reflect.DeepEqual(nil, []int{}) returns false. When comparing JSON output, both serialize to [], so this tool treats them as equal.
Only exported (capitalized) struct fields are included in json.Marshal output. If your slice contains structs with unexported fields, those fields won't appear in the JSON and won't be compared here. Use struct tags or export all relevant fields.
Serialize your Go slices to JSON (using json.Marshal) and paste the output into the two panels. Click Compare to see element-by-element differences with color coding.
Go does not support == for slices by design — it's a compile-time error. This is because slice comparison semantics are ambiguous (should it compare pointers or values?). Use reflect.DeepEqual or slices.Equal instead.
Yes. Serialize your structs to JSON with json.Marshal and paste the result. The tool compares all exported fields recursively.
Yes. This tool runs entirely in your browser. No data leaves your machine.
Go arrays can be compared with ==, but slices cannot. If you have arrays, you can still serialize them to JSON and use this tool for a visual diff.
Yes. Check the "Ignore array order" option to compare slices as unordered sets.