Implement struct encode requested by thelazyfox.
But I still suggest to use map to define an object.  It's faster and bug-free.