difference

package module
v0.0.0-...-f0e4987 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2024 License: MIT Imports: 7 Imported by: 0

README

Difference

Effortless JSON comparison for Go.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrJsonDecode = errors.New("failed to decode json")

ErrJsonDecode is the error returned when JSON decoding fails.

Functions

This section is empty.

Types

type JsonDifference

type JsonDifference struct {
	// contains filtered or unexported fields
}

JsonDifference represents the difference between two JSON structures.

func BetweenJson

func BetweenJson(expected, received io.Reader) (*JsonDifference, error)

BetweenJson compares two JSON inputs and returns their difference.

Parameters:

  • expected: io.Reader containing the expected JSON data
  • received: io.Reader containing the received JSON data

Returns:

  • *JsonDifference: A pointer to a JsonDifference struct containing the differences
  • error: An error if there was a problem decoding the JSON inputs

The function reads JSON data from both inputs, compares them, and generates a difference map.

func (*JsonDifference) GenerateReport

func (jd *JsonDifference) GenerateReport() string

GenerateReport creates a human-readable string report of the differences.

Returns:

  • string: A formatted string showing the differences between the expected and received JSON

The report uses color coding and indentation to clearly display the differences:

  • Red lines (prefixed with '-') indicate expected values
  • Green lines (prefixed with '+') indicate received values

func (*JsonDifference) HasDifferences

func (jd *JsonDifference) HasDifferences() bool

HasDifferences checks if there are any differences between the compared JSON structures.

Returns:

  • bool: true if differences exist, false otherwise

type Map

type Map = map[string]any

Map is an alias for map[string]any, representing a map with string keys and any values.

type Slice

type Slice = []any

Slice is an alias for []any, representing a slice of any type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL