Skip to content

Inconsistent order of objects in the result #16

@arnabnandikgp

Description

@arnabnandikgp

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions