Serialize a function to JSON

I need a solution where the user can write a math expression, but I found another solution, that will also be safer.

That being said, I think it would be useful to somehow be able to serialize a complete object, there should be a way to simply take what’s in memory and convert to a string (readable or not). That’s especially useful for those who don’t use databases.