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 browser

or try sample data

What is Go Slice Diff?

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.

Go Slice Comparison — Code Examples

reflect.DeepEqual (standard library)

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.

slices.Equal (Go 1.21+)

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.

Manual element-by-element comparison

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 Slice Comparison Gotchas

Slices are not comparable

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.

nil vs empty slice

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.

Struct field export rules

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.

Frequently Asked Questions

How do I compare two Go slices online?

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.

Why can't I use == to compare slices in Go?

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.

Can this compare slices of structs?

Yes. Serialize your structs to JSON with json.Marshal and paste the result. The tool compares all exported fields recursively.

Is my data safe?

Yes. This tool runs entirely in your browser. No data leaves your machine.

What about Go arrays (fixed-size)?

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.

Can I ignore slice order?

Yes. Check the "Ignore array order" option to compare slices as unordered sets.