0

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.

1
  • 1
    If you want a short hash like that, then you will have to create a database of what each hash means. Otherwise there's no way to cram that much information into a tiny string like that. (Unless each JSON is only different in a few places, then you could hash just the differences) Commented Apr 17, 2016 at 15:41

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.