hasura/graphql-engine · error

cannot convert yaml to json: %w

Error message

cannot convert yaml to json: %w

What it means

convertYamlToJsonWithIndent first converts YAML bytes to JSON via metadatautil.YAMLToJSON; if the YAML cannot be parsed into a form suitable for JSON conversion, this error wraps the failure. Callers are the metadata diff conversions for json and unified-json difftypes.

Source

Thrown at cli/commands/metadata_diff.go:298

		return errors.E(op, err)
	}

	if !file.IsDir() {
		return errors.E(
			op,
			fmt.Errorf("metadata diff only works with folder but got file %s", path),
		)
	}

	return nil
}

func convertYamlToJsonWithIndent(yamlByt []byte) ([]byte, error) {
	var op errors.Op = "commands.convertYamlToJsonWithIndent"

	jsonByt, err := metadatautil.YAMLToJSON(yamlByt)
	if err != nil {
		return nil, errors.E(op, fmt.Errorf("cannot convert yaml to json: %w", err))
	}

	var jsonBuf bytes.Buffer

	err = json.Indent(&jsonBuf, jsonByt, "", "  ")
	if err != nil {
		return nil, errors.E(op, fmt.Errorf("cannot indent json: %w", err))
	}

	return jsonBuf.Bytes(), nil
}

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Run yq over the metadata YAML files to find and fix parse errors
  2. Regenerate metadata via hasura metadata export for a known-good baseline
  3. Check for duplicate keys — strict YAML parsers reject them even when the file 'looks fine'
Defensive patterns

Strategy: validation

Validate before calling

// Go: pre-flight conversion per file
if _, err := metadatautil.YAMLToJSON(yamlBytes); err != nil {
  return fmt.Errorf("pre-flight failed for %s: %w", name, err)
}

Prevention

When it happens

Trigger: Any metadata diff with a JSON output type where one side's YAML metadata is syntactically invalid or contains structures that cannot map to JSON (e.g. non-string keys that YAMLToJSON rejects).

Common situations: Invalid YAML from hand edits, duplicate mapping keys, binary/tags in YAML that the converter rejects, or metadata files from incompatible Hasura versions with different schemas.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/e91d67060050c7ce. Report an issue: GitHub.