小编典典

如何在javascript中将JSON转换为YAML

json

我想将json字符串转换为javascript中的yaml格式。我从过去两天开始尝试在Google上找到任何解决方案或库。有适用于Java的答案,但不适用于javascript。

假设我有这样的json字符串:

{
  "json": [
    "fat and rigid"
  ],
  "yaml": [
    "skinny and flexible"
  ],
  "object": {
    "array": [
      {
        "null_value": null
      },
      {
        "boolean": true
      },
      {
        "integer": 1
      }
    ]
  }
}

转换为yaml:

json:
  - fat and rigid
yaml:
  - skinny and flexible
object:
  array:
    - null_value:
    - boolean: true
    - integer: 1

有一个在线转换器http://www.json2yaml.com/,但是如何在javascript中转换成它。


阅读 1101

收藏
2020-07-27

共1个答案

小编典典

YAML是JSON的超集。由于任何有效的JSON也是有效的YAML,因此您无需转换任何内容。

2020-07-27