Map<String, dynamic> toJson() { return { 'type': type, if (string != null) 'string': string, if (array != null) 'array': [...?array], }; }