Proper JSON encoding of variables