hasura/graphql-engine · error

cannot indent json: %w

Error message

cannot indent json: %w

What it means

The second stage of convertYamlToJsonWithIndent: YAMLToJSON succeeded, but json.Indent failed to re-indent the produced JSON. This means the intermediate JSON was malformed (invalid JSON syntax), which normally indicates the YAML produced a JSON document encoding the converter couldn't handle (multiple documents, or non-JSON-compatible output).

Source

Thrown at cli/commands/metadata_diff.go:305

		)
	}

	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. Ensure each metadata YAML file contains a single document (remove extra --- separators)
  2. Regenerate metadata files with hasura metadata export rather than concatenating manually
  3. Report/upgrade if the file is a clean export — this can indicate a CLI bug in metadatautil

Example fix

# before (multi-document file)
---
args: {}
---
version: 3
# after (single document per file)
args: {}
Defensive patterns

Strategy: validation

Validate before calling

// Go: reject multi-document YAML before converting
if bytes.Contains(yamlByt, []byte("\n---\n")) {
  return fmt.Errorf("multi-document YAML not supported")
}

Prevention

When it happens

Trigger: Metadata YAML that converts to something json.Indent rejects — e.g. multi-document YAML (--- separators) producing concatenated JSON, or YAML with values that serialize outside JSON's grammar.

Common situations: Concatenating multiple exported metadata files into one YAML with multiple documents, hand-crafted YAML with exotic tags, or a metadatautil version skew after upgrading the CLI.

Related errors


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