jsondiff

package module
v0.0.0-...-52b2619 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2023 License: MIT Imports: 4 Imported by: 0

README

jsondiff wercker status GoDoc

Reports differences between two JSONs

Example

import (
	"testing"
	"github.com/Cside/jsondiff"
)

a := []byte(`{ "foo":1, "bar":2 }`)
b := []byte(`{ "foo":1, "bar":3 }`)

if diff := jsondiff.Diff(a, b); diff != "" {
	t.Errorf("two jsons are not equal. diff:\n%s", diff)
}

output:

=== RUN   TestMain
--- FAIL: TestMain (0.00s)
        main_test.go:14: two jsons are not equal. diff:
                  {
                -   "bar": 2,
                +   "bar": 3,
                    "foo": 1
                  }
FAIL
exit status 1

Ignore values

You can ignore some values with specifiying diffopts.IgnorePath(paths []string) option.

Target values can be specified with JSON Pointer .

The following test passes.

import (
	"testing"
	"github.com/Cside/jsondiff"
	"github.com/Cside/jsondiff/diffopts"
)

a := []byte(`{ "foo": 1, "createdAt": 1517141881 }`)
b := []byte(`{ "foo": 1, "createdAt": 1528845681 }`)

if diff := jsondiff.Diff(a, b, diffopts.IgnorePaths([]string{"/createdAt"})); diff != "" {
	t.Errorf("two jsons are not equal. diff:\n%s", diff)
}

License

The MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(a, b []byte, opts ...diffopts.Option) string

func Equal

func Equal(a, b []byte, opts ...diffopts.Option) bool

func LineDiff

func LineDiff(a, b string, opts ...diffopts.Option) string

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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