json-diff icon indicating copy to clipboard operation
json-diff copied to clipboard

Add Big Number support

Open SebastianG77 opened this issue 6 years ago • 2 comments

Hi,

I need to diff JSON files which contain large numbers. Even though your module is generally very useful for comparing JSON files, it is unable to create proper diffs for JSON files containting large numbers, as it parses them by the ordinary JSON.parse() function. As a result, when comparing two files having the following JSON objects, the diff will not be recognized by this module:

file1: { "value": 3e+6000 }

file2: { "value": 3e+5000 }

However, I added optional BigNumber support. So if you now compare these two files and add the parameter -b, you will get the following diff:

{ - value: 3e+6000 + value: 3e+5000 }

I know this is a very special use case as JSON objects usually do not have big numbers, but this feature is still useful as it extends the use of this module. It also should not break anything as my changes will only be activated if the options object contains the property bigNumberSupport. Moreover, all previous test cases are still running. I also added some additional test cases to check if this feature works and I am willing to add some more if desired.

Please let me know soon, if you are intersted in merging this pull request, as I also personally need this feature.

Otherwise I at least would like to publish the fork to npm by myself if you don't mind.

Looking forward for some response.

SebastianG77 avatar Feb 10 '19 17:02 SebastianG77

Hi,

I just wanted to let you know that I now published my fork at npm (https://www.npmjs.com/package/big-json-diff).

I hope this is okay for you. I still will appreciate if you merge my pull request.

SebastianG77 avatar Feb 19 '19 20:02 SebastianG77

Hi @SebastianG77 ! Thank you, this seems like a useful change. However, we've converted our codebase over to ES6 and also cleaned up the way options are handled in index.js. If you can implement your change against the current codebase we can merge it in.

ewoudenberg avatar Mar 06 '22 18:03 ewoudenberg