JSON.stringify() and JSON.parse() - Best practices

Hello everyone. In my app I use lot of POST and GET methods, also many times I cache data to local storage and I have never used JSON.stringify or JSON.parse. I don’t face any problems without using it for now. In terms of performance, is it better to cache data as string (stringify it) or object? Should I use these two JSON methods in general?

What are your opinions and experiences?

Thanks.

It makes absolutely no difference. If for technical reasons the underlying storage mechanism can only handle strings, it is the responsibility of the storage provider (I would highly suggest using Ionic Storage instead of directly dealing with localStorage here) to marshal and unmarshal your objects.

See above. If they’re needed, a proper library will be calling them for you. App code shouldn’t need to be worrying about this.

1 Like

Thank you for clarifying.