json_canonicalize.hpp file
Rewrite alias keys in JSON text to canonical gtopt names.
Sits in front of daw::json::from_json<Planning>(...) and rewrites alternative input key names (PyPSA p_nom, pandapower max_p_mw, PLEXOS Max Capacity, PSR SDDP GerMax, PLP PotMax, gtopt-modern marginal_cost, …) to the canonical name (e.g. pmax) expected by the strict daw::json contract.
Rationale (docs/analysis/naming-conventions.md §10.4):
daw::jsonbinds every contract member to a single literal name at compile time and gtopt usesStrictParsePolicy(UseExactMappingsByDefault::yes), so an alias key in raw JSON is rejected before any post-parse hook gets a chance to fold it.- Walking the JSON token-by-token before parsing lets us rewrite only the keys, never the values — safe even when a value string happens to equal an alias name (e.g.
"description": "max_demand is deprecated").
The rewriter consumes the (alias → canonical) map from NamesRegistry::instance(). Aliases must be globally unique across element types (the registry enforces this at load time), so the rewriter does not need element-type context.
Aliases flagged "deprecated": true (renamed gtopt keys such as annual_loss → annual_standing_loss) are still rewritten, but log a once-per-process spdlog::warn, and an object that sets both the deprecated alias and its canonical key throws std::invalid_argument (after the rewrite one of the two values would be silently lost).
Namespaces
- namespace gtopt