Move JSON encoding/decoding into Client