keploy / keploy/jsondiff

Inconsistent order of objects in the result

Open
#16 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
9
Forks
10
PR merge metrics
No merged PRs in 30d

Description

Hi I am new to keploy and to this package, I was just testing and playing around this package locally using some examples in its test file, and it seems that the output for the diffs are not consistent in every run, as one can see that if I run the example with the two input json given below multiple times the result tends to vary, though objectively the order of key-value pairs in json do not matter and two json's with different order of same set of key-value pairs are considered equivalent, should it not be better that it yields consistent results and not vary with each run and since this package is being used for aesthetically printing the differences between two given json with colored diffs , in my opinion it will also be logical to have the diffs in the same order of key-value pair so that the user can grasp the differences between two json in a more pronounced way.
```
json1 := []byte("{\"books\":[{\"title\":\"Book A\",\"author\":{\"name\":\"Author 1\"}},{\"title\":\"Book B\",\"author\":{\"name\":\"Author 2\"}}]}")
json2 := []byte("{\"books\":[{\"title\":\"Book B\",\"author\":{\"name\":\"Author 2\"}},{\"title\":\"Book A\",\"author\":{\"name\":\"Author 1\"}}]}")

```
we have the two altering outputs
```
EXPECT | ACTUAL
-----------------------------------------------------+-----------------------------------------------------
{ | {
[0]: { | [0]: {
"title": "Book B" , | "title": "Book A" ,
"author": { | "author": {
"name": "Author 2" , | "name": "Author 1" ,
} | }
} | }
[1]: { | [1]: {
"title": "Book A" , | "title": "Book B" ,
"author": { | "author": {
"name": "Author 1" , | "name": "Author 2" ,
} | }
} | }
} | }
|

```

and
```
EXPECT | ACTUAL
-----------------------------------------------------+-----------------------------------------------------
{ | {
[0]: { | [0]: {
"title": "Book B" , | "title": "Book A" ,
"author": { | "author": {
"name": "Author 2" , | "name": "Author 1" ,
} | }
} | }
[1]: { | [1]: {
"author": { | "author": {
"name": "Author 1" , | "name": "Author 2" ,
} | }
"title": "Book A" , | "title": "Book B" ,
} | }
} | }
|

```
notice how the order in the outputs changes in two different runs(color not added.) and it seems there can be more permutations possible( to be precise 8 in total as evident from the list of hashes in the test file).

Contributor guide

Open the contributing guide

Research direction

Start by running the JSON example from the issue in the referenced test file repeatedly and inspect where the diff output order is determined. The work is done when equivalent inputs produce a stable ordering on every run and the behavior is covered by a test.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.