jsondiff

package module
v0.0.0-...-cbd5be2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2019 License: MIT Imports: 7 Imported by: 0

README

JSONDIFF

A simple little tool that produces readable diff of 2 JSON-able (read "convertible to map[string]interface{}") objects. Useful for diagnostics or debugging

Installation

go get github.com/elgris/jsondiff

Examples of the output

screen shot 2016-05-20 at 13 03 06

Limitation

  • Coloured output tested with bash only, not sure how it will behave with other terminals.
  • The tool converts input data into map[string]interface{} with json encoding/decoding. Hence, types of input map will change during unmarshal step: integers become float64 and so on (check https://golang.org/pkg/encoding/json/ for details).

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(diff Diff) []byte

Format produces formatted output for a diff that can be printed. Uses colourization which may not work with terminals that don't support ASCII colouring (Windows is under question).

Types

type Diff

type Diff struct {
	// contains filtered or unexported fields
}

Diff is a result of comparison operation. Provides list of items that describe difference between objects piece by piece

func Compare

func Compare(a, b interface{}) Diff

Compare produces list of diff items that define difference between objects "a" and "b". Note: if objects are equal, all diff items will have Resolution of type TypeEquals

func CompareBytes

func CompareBytes(a, b []byte) Diff

CompareBytes produces list of diff items that define difference between JSON encoded bytes "a" and "b". Note: if objects are equal, all diff items will have Resolution of type TypeEquals

func (*Diff) Add

func (d *Diff) Add(item DiffItem)

Add adds new item to diff object

func (Diff) IsEqual

func (d Diff) IsEqual() bool

IsEqual checks if given diff objects does not contain any non-equal element. When IsEqual returns "true" that means there is no difference between compared objects

func (Diff) Items

func (d Diff) Items() []DiffItem

Items returns list of diff items

type DiffItem

type DiffItem struct {
	Key        string
	ValueA     interface{}
	Resolution ResolutionType
	ValueB     interface{}
}

DiffItem defines a difference between 2 items with resolution type

type ResolutionType

type ResolutionType int

ResolutionType defines a type of comparison: equality, non-equality, new sub-diff and so on

const (
	TypeEquals ResolutionType = iota
	TypeNotEquals
	TypeAdded
	TypeRemoved
	TypeDiff
)

Jump to

Keyboard shortcuts

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