【发布时间】:2019-06-25 04:39:25
【问题描述】:
我正在尝试将 JSON 合并到 YAML 文件中。
YAML 看起来像这样:
文件节拍输入:
- type: log
<incorporate here with a single level indent>
enabled: true
paths:
假设你有以下变量:
a = { processors: { drop_event: { when: { or: [ {equals: { status: 500 }},{equals: { status: -1 }}]}}}}
我想将它合并到现有的 YAML 中。
我试过用:
JSON.parse((a).to_json).to_yaml
应用此功能后,我得到了一个有效的 YAML,但没有缩进(所有行都必须缩进),并且带有一个“---”,这是 Ruby 在 YAML 中的新文档。
结果:
filebeat.inputs:
- type: log
---
processors:
drop_event:
when:
or:
- equals:
status: 500
- equals:
status: -1
enabled: true
我正在寻找的结果:
filebeat.inputs:
- type: log
processors:
drop_event:
when:
or:
- equals:
status: 500
- equals:
status: -1
enabled: true```
【问题讨论】:
标签: json ruby yaml chef-infra