Updated validation of input and Json encoding and decoding