Preflight Checklist

  • [x] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Problem Description

Describe the feature

When using viper.WriteConfig or a custom write implementation (via marshalWriter), values in the internal config map like "true" (string) are written to the output file (e.g., YAML) as "true" instead of true (boolean).

This usually happens when config values are updated or set programmatically from sources that store everything as strings (e.g., CLI flags, env vars, encrypted configs, etc).

Problem

This causes configuration types to be misleading in output YAML:

```yaml packager: example_project: trust: "true" # should be: true (bool)

Proposed Solution

A type normalization step before encoding, where "true" / "false" strings could be coerced into booleans (similarly for numeric strings).

A hook/callback mechanism (e.g., BeforeMarshal(func(map[string]any) map[string]any)) so users can implement normalization logic themselves before Viper marshals the config.

An option or flag like viper.NormalizeTypesOnWrite(true) that opts into this behavior.

Alternatives Considered

No response

Additional Information

No response

Comment From: github-actions[bot]

Issues with no activity for 30 days are marked stale and subject to being closed.