mirek / node-rus-diff

JSON diff
MIT License
125 stars 11 forks source link

Diff Subarrays in JSON will fail over complete Array #10

Open ognif opened 4 years ago

ognif commented 4 years ago

After comparing this structure (I only copy one JSON, the other only differ in dates) the result report that the whole properties subarray is not the same. But there is only one kind of the Properties array that has different data.

{ "response": [ { "uuid": "aa03ddbffe59448fb8a56f6b80e650053", "cluserId": 166699, "filenameSource": "test_img_191021a", "fileExt": "png", "createTimeStamp": "2019-10-21T13:53:58.620Z", "md5source": "a02fe9af9ae428ffac9788a81f80d545", "lastChangeTimeStamp": "2019-10-21T13:54:00.280Z", "uniqueId": "16923239829449398188362AT", "fileName": "Test_IMG_191021A.png", "title": "Test_IMG_191021A", "language": "##", "clipType": -1, "categories": [ { "id": 127845, "type": "directory", "name": "root", "titles": [ { "value": "root", "language": "en" } ], "activated": true } ], "gema": false, "validFrom": "2019-10-21T13:53:57.000Z", "rating": 99, "resolution": "1900x1429", "duration": 0, "fps": 0, "properties": [ { "key": "language", "value": "##", "language": "##" }, { "key": "filesize-source", "value": "495429", "language": "##" }, { "key": "title", "value": "Test_IMG_191021A", "language": "##" }, { "key": "md5-source", "value": "a02fe9af9ae428ffac9788a81f80d545", "language": "##" }, { "key": "filename-source", "value": "Test_IMG_191021A.png", "language": "##" }, { "key": "version", "value": "0", "language": "##", "position": 0, "timestamp": "2019-10-21T13:53:58.620Z" }, { "key": "resolution", "value": "1900x1429", "language": "##" }, { "key": "format", "value": "png", "language": "##" } ], "products": [ { "title": "16923239829449398188362AT", "requestKey": "Test_IMG_191021A", "keyType": 100 } ], "activated": true, "fileSize": 495429, "importTime": "2019-10-21T13:53:58.620Z", "fileType": "Picture", "links": [ { "location": "https://asset.andy0815.com/is/169232/1b8da60de9afb3063f77e411d976bfac8/c3/-/aa03ddbffe59448fb8a56f6b80e650053", "fileType": "png", "name": "iapi", "fileSize": 495429, "linkResolution": "1900x1429" }, { "location": "https://asset.andy0815.com/ad/169232/1b8da60de9afb3063f77e411d976bfac8/c3/-/aa03ddbffe59448fb8a56f6b80e650053", "fileType": "png", "name": "source", "fileSize": 495429, "linkResolution": "1900x1429" } ], "processStatus": { "currentStep": "Published" }, "createUserId": 172775 } ] }

A cross check with just the properties array will successful report only the { '5.timestamp': '2020-01-14T13:26:30.036Z' } as different.

Iam not sure whether this is an issue or wrong usage.

ognif commented 4 years ago

Sorry I do not know why the "code" option will destroy the format. I have attached the json for better reading as text file. data.txt

mirek commented 4 years ago

Can you try latest master, please?

ognif commented 4 years ago

I have tested the last master now and it works better. But I think there is a bug with iterate through this sub arrays. I think you compare "index" and not the keys. Means you compare org.properties[0] with result.properties[0] the right way will be org.properties.language with result.properties.langauge. Maybe the whole module need a strict sort order of keys?

I have added three files to this post. org.txt, result.txt compare.txt compare.txt org.txt result.txt

ognif commented 4 years ago

I made a quick test. The top level of keys the module works well. No matter what kind of order, it compares. But with sub arrays and keys it do not iterate the same.

mirek commented 4 years ago

Oh yes, the order in sub arrays is tricky because you don't know if we should compare it as a set or as an ordinary array. The best may be to pre-sort sub arrays that needs to be compared as sets? I'll have a look at it but probably not before the weekend. Thanks for input files. I'll probably rewrite the whole thing in js as well.

ognif commented 4 years ago

Hi, any news about the issue?

mirek commented 4 years ago

Not yet, I don't promise to fix this anytime soon unfortunatelly. I've started rewrite but I don't know how long it'll take.

ognif commented 4 years ago

That is a bad information. I suggest to make a big Notice to your GitHub Page that it cannot compare Arrays in JSON Objects because it expect a strict order of array items.

alvitoraidhy commented 3 years ago

Any updates on this?