Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SkippedArrayElement ¶
func SkippedObjectProperty ¶
Types ¶
type Difference ¶
type Difference int
const ( FullMatch Difference = iota SupersetMatch NoMatch FirstArgIsInvalidJson SecondArgIsInvalidJson BothArgsAreInvalidJson )
func Compare ¶
func Compare(a, b []byte, opts *Options) (Difference, string)
Compares two JSON documents using given options. Returns difference type and a string describing differences.
FullMatch means provided arguments are deeply equal.
SupersetMatch means first argument is a superset of a second argument. In this context being a superset means that for each object or array in the hierarchy which don't match exactly, it must be a superset of another one. For example:
{"a": 123, "b": 456, "c": [7, 8, 9]}
Is a superset of:
{"a": 123, "c": [7, 8]}
NoMatch means there is no match.
The rest of the difference types mean that one of or both JSON documents are invalid JSON.
Returned string uses a format similar to pretty printed JSON to show the human-readable difference between provided JSON documents. It is important to understand that returned format is not a valid JSON and is not meant to be machine readable.
func (Difference) String ¶
func (d Difference) String() string
type Options ¶
type Options struct { Normal Tag Added Tag Removed Tag Changed Tag Skipped Tag SkippedArrayElement func(n int) string SkippedObjectProperty func(n int) string Prefix string Indent string PrintTypes bool ChangedSeparator string // When provided, this function will be used to compare two numbers. By default numbers are compared using their // literal representation byte by byte. CompareNumbers func(a, b json.Number) bool // When true, only differences will be printed. By default, it will print the full json. SkipMatches bool }
func DefaultConsoleOptions ¶
func DefaultConsoleOptions() Options
Provides a set of options that are well suited for console output. Options use ANSI foreground color escape sequences to highlight changes.
func DefaultHTMLOptions ¶
func DefaultHTMLOptions() Options
Provides a set of options that are well suited for HTML output. Works best inside <pre> tag.
func DefaultJSONOptions ¶
func DefaultJSONOptions() Options
Provides a set of options in JSON format that are fully parseable.