1

Bumped into this while trying to cache objects into localstorage. seems that localstorage currently doesn't support objects with methods/object Instances etc. just POJO that are serialized into a string. In python there's pickle that can handle this (or marshal before it) but I couldn't find a js equivalent. Since I guess I'm not the first Js dev to need this feature I guess there are already proven solutions (either in patterns or external libs) to this problem which I'm missing.

Basically I'm looking for a way to call serialize(object) into a json/string and later deSerialize(objString) that would return the original object/instance etc.

The answer can be some lib and doesn't have to be part of the js standard library.

1 Answer 1

2

I use JSONfn do that. It has its own stringify/parse methods that save functions as well as ordinary JSON data.

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

2 Comments

can it handle an instance? or just an object?
It can handle any object with properties and methods. Check out the documentation. :)

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.