Skip to content
This repository has been archived by the owner on Jul 25, 2020. It is now read-only.
/ go-jsoneq Public archive

deprecated: Go library to check if two values are equal as JSON

License

Notifications You must be signed in to change notification settings

suzuki-shunsuke/go-jsoneq

Repository files navigation

go-jsoneq

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

Go library to check if two values are equal as JSON

Deprecated: Please use suzuki-shunsuke/go-dataeq instead of this library

https://github.com/suzuki-shunsuke/go-dataeq

Example

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