adding json encoding and decoding