go-jsoneq

module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2020 License: MIT

README

go-jsoneq

GoDoc Build Status codecov Go Report Card GitHub last commit GitHub tag License

Golang library to check if two values are equal as JSON.

package jsoneq_test

import (
	"fmt"
	"log"

	"github.com/suzuki-shunsuke/go-jsoneq/jsoneq"
)

type (
	Foo struct {
		Foo string `json:"foo"`
	}
)

func checkResult(b bool, err error) {
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(b)
}

func Example() {
	b, err := jsoneq.Equal(
		Foo{Foo: "bar"},
		map[string]string{"foo": "bar"},
	)
	checkResult(b, err)

	// when a type of value is []byte, it is treated as JSON string
	b, err = jsoneq.Equal(
		Foo{Foo: "bar"},
		[]byte(`{"foo": "bar"}`),
	)
	checkResult(b, err)

	// Output:
	// true
	// true
}

License

MIT

Directories

Path Synopsis
Package jsoneq checks if two values are equal as JSON.
Package jsoneq checks if two values are equal as JSON.

Jump to

Keyboard shortcuts

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