Skip to content

Empty patch when compare two arrays #14

Description

@tochti

Hello,

first thanks for your effort creating this library.

I was wondering if the following behavior is intended?

Actual Behavior

If the following code is executed the result is an empty patch.
The reason for that is that the 2nd item in o2 is the "same" item like the item in o1.

import (
	"fmt"

	"github.com/mattbaird/jsonpatch"
)

func main() {

	o1 := []byte(`{"Items":[{"K":1}]}`)
	o2 := []byte(`{"Items":[{"K":1},{"K":1}]}`)

	patch, err := jsonpatch.CreatePatch(o1, o2)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println("Patch", patch)

}

Expected Behavior

I did expect to get the following patch

[{"op": "add", "path": "/Items/1", "value": {"K":1}}]

Specifications

Version: newest (go get github.com/mattbaird/jsonpatch)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions