Add flag support for JSON deserializer

This PR adds the flag support for the JSON deserializer and targets #361.
Please review carefully and ask me to add more tests if you like!
Just allocate `buf` on the stack.