Web Version Guide1 分钟

锚点保留功能

如何保留YAML锚点

锚点保留功能

YAMLforge的关键功能:锚点保留


🔗 什么是YAML锚点?

YAML锚点允许您在多个位置重用相同的数据:

# 锚点定义
defaults: &defaults
  timeout: 30
  retries: 3

# 使用别名重用
production:
  <<: *defaults
  host: prod.example.com

staging:
  <<: *defaults
  host: staging.example.com

❌ 其他工具的问题

其他转换器会展开并丢失锚点

{
  "defaults": {"timeout": 30, "retries": 3},
  "production": {"timeout": 30, "retries": 3, "host": "prod.example.com"},
  "staging": {"timeout": 30, "retries": 3, "host": "staging.example.com"}
}

转换回YAML不会恢复锚点。


✅ YAMLforge解决方案

YAMLforge 将锚点信息保留为元数据

如何使用

  1. 开启"保留锚点"选项
  2. 执行转换
  3. JSON → YAML转换时恢复锚点

📊 支持状态

锚点类型支持
基本 &name
别名 *name
合并键 <<
嵌套锚点
标签
#anchor#yaml#feature#preservation