Open slayerjain opened 3 months ago
Hey there! I would like to try fixing this.
@Akash-Singh04 Please feel free :)
@shivamsouravjha please review this once there is a PR.
@slayerjain Could you provide the exact application in which the jsonarr diff are not visible. It would make it easier for me to develop a solution if you could provide it. Thanks
Hey @Akash-Singh04 ! You can try with Pet Clinic sample app to replicate the error. This happens when any element in an array changes and everything after that value would be shown in different color.
According to my investigation, the error lies in here:
func calculateJSONDiffs(json1 []byte, json2 []byte) (string, error) {...}
and func separateAndColorize(diffStr string, noise map[string][]string) (string, string) {...}
The calculateJSONDiffs
is not catered to handle json arrays, similarly the separateaAndColourize
function also doesn't work for json arrays, only for Jsons.
Please let me know how we can refactor this to solve the issue
Hey @Akash-Singh04 in calculateJSONDiffs
the Format
function does have formatArray and formatObject.
Can you please explain the error in detail.
I am referring to these two functions
The separateAndColourize
function is documented to only work with Json
The function sprintJSONDiff
which calls calculateJSONDiffs
and separateaAndColourize
is also documented to only work with JSONS
Hence, when an array of Jsons is passed, sprintDiff
is called instead
This according to me is the cause of the problem.
Agreed this seems to be the problem with the calculateJSONDiffs
as it throws error on diff.Compare.
The dependency seems to be inactive for a while and thus we're looking for alternatives as well.
Alright, let me know what is the alternative approach to this. Had a lot of fun learning and debugging this!
Since we switched to GJSON from gojsondiff, this issue was resolved and can be closed @slayerjain
Is there an existing issue for this?
Current behavior
Currently is there is a diff in a JSON array, keploy would highlight the entire string after the faulty string. This makes it hard to see the diff. Eg:
It should only highlight the difference and leave the rest. The potential reason could be that the JSON array diff compare is not implemented for JSON Array type or there is incorrect matching of type.
Steps to reproduce
Environment
None
Version
Cloud
Repository
keploy