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!
Was done, diff does not outdate. Feel free to remove the comments on this diff.