jsondiff: github.com/nsf/jsondiff Index | Files | Directories

package jsondiff

import "github.com/nsf/jsondiff"


Package Files


type Difference Uses

type Difference int
const (
    FullMatch Difference = iota

func Compare Uses

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 Uses

func (d Difference) String() string

type Options Uses

type Options struct {
    Normal           Tag
    Added            Tag
    Removed          Tag
    Changed          Tag
    Prefix           string
    Indent           string
    PrintTypes       bool
    ChangedSeparator string

func DefaultConsoleOptions Uses

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 Uses

func DefaultHTMLOptions() Options

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

func DefaultJSONOptions Uses

func DefaultJSONOptions() Options

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

type Tag Uses

type Tag struct {
    Begin string
    End   string



Package jsondiff imports 5 packages (graph) and is imported by 4 packages. Updated 2020-08-20. Refresh now. Tools for package owners.