dev
dev

Reputation: 745

Javascript packing object to hash string

I have an object that is updating with every mouse click and it could be loaded with the page. I am trying to compress it into a hash ( so users can link their variations Ex:/page#HsaWiSAU, but I am having trouble making it into a readable link.

So far I've tried couple compressing libs but nothing. I was close with the lz-string one, but when it compresses it, there are those huge strings.

{
    "FX": {
        "row1": {
            "sp6111": {
                "ranks": 5,
                "curr": 1
            },
            "sp6114": {
                "ranks": 5,
                "curr": 0
            }
        },
        "row2": {
            "sp6121": {
                "ranks": 1,
                "curr": 0
            },
            "sp6122": {
                "ranks": 1,
                "curr": 0
            },
            "sp6123": {
                "ranks": 1,
                "curr": 0
            }
        }...
    },
    "CX": {},
    "RX": {}
}

Can you suggest me a lib I should look at or how to write my own ? I get that the large strings are because I stringify this and compress the entire string, so I need a better, more human-friendly solution.

Upvotes: 0

Views: 234

Answers (2)

stan
stan

Reputation: 4995

If you want to generate a user friendly hash, look into HashIds

Then you can easily generate a hash by passing the result of JSON.stringify(obj) into that library.

Upvotes: 2

Devank
Devank

Reputation: 159

You can use redis or some key value database for that. I would prefer to use redis.

Upvotes: 1

Related Questions