hasura/graphql-engine · error

parsing yaml metadata to json: %w

Error message

parsing yaml metadata to json: %w

What it means

When applying YAML-mode metadata, the CLI first converts the local YAML file to JSON via metadatautil.YAMLToJSON. This error means the local metadata file is not valid YAML (or contains YAML structures that cannot be represented in JSON), so the apply cannot proceed.

Source

Thrown at cli/commands/metadata_handlers.go:373

	}

	if o.DryRun {
		if len(o.rawOutput) == 0 {
			o.rawOutput = string(rawOutputFormatJSON)
		}

		err := writeByOutputFormat(o.EC.Stdout, localMetadataBytes, rawOutputFormat(o.rawOutput))
		if err != nil {
			return errors.E(op, fmt.Errorf("displaying metadata failed: %w", err))
		}

		return nil
	}

	if mode == cli.MetadataModeYAML {
		localMetadataBytes, err = metadatautil.YAMLToJSON(localMetadataBytes)
		if err != nil {
			return errors.E(op, fmt.Errorf("parsing yaml metadata to json: %w", err))
		}
	}

	var metadata any

	err = json.Unmarshal(localMetadataBytes, &metadata)
	if err != nil {
		return errors.E(op, fmt.Errorf("parsing metadata as json: %w", err))
	}

	if o.EC.Config.Version == cli.V2 {
		_, err := cli.GetCommonMetadataOps(o.EC).
			ReplaceMetadata(bytes.NewReader(localMetadataBytes))
		if err != nil {
			return errors.E(op, err)
		}

		return nil

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Lint the file with yq or a YAML validator to pinpoint the syntax error
  2. Fix indentation (spaces, not tabs), remove merge-conflict markers, deduplicate keys
  3. If unsure which section breaks, split the file and validate sections incrementally
  4. Consider regenerating the file via `metadata export -o yaml` from a known-good server and re-applying your changes on top

Example fix

# before
hasura metadata apply  # parsing yaml metadata to json (bad indentation)
# after
yq metadata.yaml  # locate the error, fix indentation, then re-run apply
Defensive patterns

Strategy: validation

Validate before calling

// validate YAML before apply (YAML mode)
data, _ := os.ReadFile(ec.MetadataFile)
var v any
if err := yaml.Unmarshal(data, &v); err != nil {
  return fmt.Errorf("metadata YAML invalid: %w", err)
}

Try / catch

if err := apply(o, cli.MetadataModeYAML); err != nil {
  if strings.Contains(err.Error(), "parsing yaml metadata to json") {
    // run yq on the file to find the syntax error, fix, retry
  }
}

Prevention

When it happens

Trigger: `metadata apply` in YAML mode where the metadata file has YAML syntax errors: bad indentation, tabs, duplicate keys, unclosed quotes, or YAML aliases/constructs with no JSON equivalent (e.g. non-string map keys are fine, but binary/odd tags are not).

Common situations: Hand-edited metadata.yaml with indentation mistakes; copy-pasted snippets using tabs instead of spaces; merge conflict markers (<<<<<<<) left in the file; YAML converted from another tool with unsupported features like duplicate keys.

Related errors


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