beenotung / compress-json

Store JSON data in space efficient manner
https://www.npmjs.com/package/compress-json
BSD 2-Clause "Simplified" License
108 stars 6 forks source link

Assertion failed for large hard structured json. #5

Closed varyandeveloper closed 3 years ago

varyandeveloper commented 3 years ago

Great work, but I found another issue that prevents me to use this package as a JSON pack/unpack tool.

` const data = require('./my-data.json'); const { compress, decompress } = require('compress-json'); const assert = require('assert');

assert.deepStrictEqual(decompress(compress(data)), data); `

beenotung commented 3 years ago

Thanks for reporting bug, could you share a sample of the json file?

varyandeveloper commented 3 years ago

Let me share the link to the file.

https://drive.google.com/file/d/1dUx7IAXmxD7ifuO5_hyeQnoEmC6GY8d3/view?usp=sharing

beenotung commented 3 years ago

I can confirm (reproduce) the bug with your sample file.

For example, the original "name": "__THECONN__", becomes "name": ["__THECONN__"],.

I'm looking into why.

beenotung commented 3 years ago

I've reduced it to a minimal data that reproduce the bug.

Original Data:

{
  "any-1": {
    "key-and-value": "any-3"
  },
  "any-2": "key-and-value"
}

Decompressed Data:

{
  "any-1": {
    "key-and-value": "any-3"
  },
  "any-2": [
    "key-and-value"
  ]
}

It seems to happen when a string value appears both as object key and object value. Will try to figure out why.

beenotung commented 3 years ago

The cause is identified. Related to caching (The array of Object.keys() are converted into string (using array.join(',')).

Will fix it soon

varyandeveloper commented 3 years ago

Awesome,

Thank you a lot for your fast response and effort to make it better.

I really appreciate, in fact, this package is the best for compressing JSON as it makes content smaller than other popular packages like compressed-json and jsonpack.

beenotung commented 3 years ago

Applied a fix and it can pass the reduced test case. It is released as 2.0.0.

However, it seems still cannot pass the provided sample file. Continue debugging :muscle:

beenotung commented 3 years ago

Thank you for your appreciation. Indeed, this package is inspired from the algorithms used in the two mentioned packages.

beenotung commented 3 years ago

The reported bug(s) should have been fixed in compress-json@2.0.1. @varyandeveloper, might you confirm that with your data set? Thanks.

varyandeveloper commented 3 years ago

Yes, I can confirm that this issue was fixed.

Thank you again.