jsondiff

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DiffType

type DiffType int
const (
	FullMatch DiffType = iota
	SupersetMatch
	NoMatch
	FirstArgIsInvalidJson
	SecondArgIsInvalidJson
	BothArgsAreInvalidJson
)

func Compare

func Compare(a, b []byte, opts ...Options) (DiffType, string)

Compare /** 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 (DiffType) String

func (d DiffType) 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

DefaultConsoleOptions Provides a set of options that are well suited for console output. Options DefaultConsoleOptions use ANSI foreground color escape sequences to highlight changes.

func DefaultHtmlOptions added in v1.5.2

func DefaultHtmlOptions() Options

DefaultHtmlOptions Provides a set of options that are well suited for HTML output. Works best inside <pre> tag.

func DefaultJsonOptions added in v1.5.2

func DefaultJsonOptions() Options

DefaultJsonOptions Provides a set of options in JSON format that are fully parseable.

type Tag

type Tag struct {
	Begin string
	End   string
}

Jump to

Keyboard shortcuts

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