Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to unmarshal valid json #15

Open
kuznet1 opened this issue Jan 18, 2017 · 5 comments
Open

Failed to unmarshal valid json #15

kuznet1 opened this issue Jan 18, 2017 · 5 comments
Labels

Comments

@kuznet1
Copy link

kuznet1 commented Jan 18, 2017

$ echo [1] > 1.json
$ echo [2] > 2.json
$ jd 1.json 2.json

Failed to unmarshal file: json: cannot unmarshal array into Go value of type map[string]interface {}
exit status 3

@yudai yudai added the bug label Jan 20, 2017
@yudai
Copy link
Owner

yudai commented Jan 20, 2017

Thanks for the report.
I'll take a look into the issue.

@blaskovicz
Copy link

blaskovicz commented Feb 8, 2017

It looks like it's because the Compare() function assumes that the outer layer of the JSON is an object, not an array. The function.

As an easy workaround for now, you can always wrap the actual object in another object.
Example: {"_": expectedData } vs {"_": actualData }.

@yudai
Copy link
Owner

yudai commented Mar 5, 2017

Working on the fix_15 branch.

@kidandcat
Copy link

it cannot properly unmarshall this too: {["this is valid json"]}

@cold-bin
Copy link

maybe, this way is help to you:

func AnyJsonDiff(left interface{}, right interface{}) (gojsondiff.Diff, error) {
	type Container struct {
		Payload any
	}
	
	leftBs, err := json.Marshal(Container{left})
	if err != nil {
		return nil, err
	}
	rightBs, err := json.Marshal(Container{right})
	if err != nil {
		return nil, err
	}
	
	return gojsondiff.New().Compare(leftBs, rightBs)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants