mikefarah/yq · error

no support for output format

Error message

no support for output format

What it means

yq's encode operator looks up an Encoder for the requested output format via configureEncoder(). If the format string doesn't match any registered format, or the format is encoder-only-unsupported (e.g. built with a build tag that excludes it, like yq_noxml, so the factory returns nil), encodeToString returns this error. It means the library cannot serialize to the requested format in this binary.

Source

Thrown at pkg/yqlib/operator_encoder_decoder.go:40

		var prefs = ConfiguredYamlPreferences.Copy()
		prefs.Indent = indent
		prefs.ColorsEnabled = false
		return NewYamlEncoder(prefs)
	case XMLFormat:
		var xmlPrefs = ConfiguredXMLPreferences.Copy()
		xmlPrefs.Indent = indent
		return NewXMLEncoder(xmlPrefs)
	}
	return format.EncoderFactory()
}

func encodeToString(candidate *CandidateNode, prefs encoderPreferences) (string, error) {
	var output bytes.Buffer
	log.Debugf("printing with indent: %v", prefs.indent)

	encoder := configureEncoder(prefs.format, prefs.indent)
	if encoder == nil {
		return "", errors.New("no support for output format")
	}

	printer := NewPrinter(encoder, NewSinglePrinterWriter(bufio.NewWriter(&output)))
	err := printer.PrintResults(candidate.AsList())
	return output.String(), err
}

type encoderPreferences struct {
	format *Format
	indent int
}

/* encodes object as yaml string */
var chomper = regexp.MustCompile("\n+$")

func encodeOperator(_ *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
	preferences := expressionNode.Operation.Preferences.(encoderPreferences)
	var results = list.New()

View on GitHub (pinned to 8b5af0694b)

Solutions

  1. Check the format name against `yq --help` output and use an exact supported value (yaml, json, xml, csv, tsv, props, etc.).
  2. If using a reduced build, rebuild yq without the yq_no<format> build tag (full build: go build -o yq .).
  3. Upgrade to a recent yq release if the required output format is newer than your binary.

Example fix

// before
yq -o yml '.' file.yaml
// after
yq -o yaml '.' file.yaml
Defensive patterns

Strategy: validation

Validate before calling

const supported = ["yaml","y","json","j","props","p","csv","tsv","xml","c","lua"]
if !supported.includes(formatName) {
  throw new Error(`unsupported output format: ${formatName}`)
}

Prevention

When it happens

Trigger: Running `yq -o <fmt>` (or encode_xml / to_json style operators) with a misspelled or unsupported format name; using a slim build compiled with `yq_no<format>` tags where that encoder's factory returns nil; calling encode with a format registered with a nil encoder factory.

Common situations: Typo in -o flag (e.g. `-o yml` instead of `-o yaml` in versions without that alias); using a small/tiny build (build_small-yq.sh / tinygo) that strips format support; older yq versions lacking a newer format like HCL or CSV.

Related errors


AI-assisted analysis of mikefarah/yq@8b5af0694b (2026-09-05). Data as JSON: /api/errors/afb70aeedbcc85f9. Report an issue: GitHub.