jsoneq

package
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 Imports: 3 Imported by: 8

Documentation

Overview

Package jsoneq checks if two values are equal as JSON.

Example
package main

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 main() {
	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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(x interface{}) (interface{}, error)

Convert converts a given value to an object which can be checked if it is equal to the other value as JSON.

func ConvertByte

func ConvertByte(b []byte) (interface{}, error)

ConvertByte converts a byte array to an object which can be checked if it is equal to the other value as JSON.

func Equal

func Equal(x, y interface{}) (bool, error)

Equal checks if two values are equal as JSON.

Types

This section is empty.

Jump to

Keyboard shortcuts

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