func()

in tools/mc2bq/pkg/schema/schema.go [49:67]


func (s *ExporterSchema) MarshalJSON() ([]byte, error) {
	// We need to implement the Marshaller interface because bigquery.Schema marshals with
	// ToJSONFields() insteald of implementing the Marshaller interface.

	myType := reflect.TypeOf(s).Elem()
	myValue := reflect.ValueOf(s).Elem()
	res := map[string]json.RawMessage{}
	for i := 0; i < myType.NumField(); i++ {
		key := myType.Field(i).Tag.Get("json")
		schema := myValue.Field(i).Interface().(bigquery.Schema)
		fields, err := schema.ToJSONFields()
		if err != nil {
			return nil, err
		}
		res[key] = fields

	}
	return json.Marshal(res)
}