• <bdo id='yDM2D'></bdo><ul id='yDM2D'></ul>
        <i id='yDM2D'><tr id='yDM2D'><dt id='yDM2D'><q id='yDM2D'><span id='yDM2D'><b id='yDM2D'><form id='yDM2D'><ins id='yDM2D'></ins><ul id='yDM2D'></ul><sub id='yDM2D'></sub></form><legend id='yDM2D'></legend><bdo id='yDM2D'><pre id='yDM2D'><center id='yDM2D'></center></pre></bdo></b><th id='yDM2D'></th></span></q></dt></tr></i><div id='yDM2D'><tfoot id='yDM2D'></tfoot><dl id='yDM2D'><fieldset id='yDM2D'></fieldset></dl></div>

      1. <tfoot id='yDM2D'></tfoot>

        <small id='yDM2D'></small><noframes id='yDM2D'>

        <legend id='yDM2D'><style id='yDM2D'><dir id='yDM2D'><q id='yDM2D'></q></dir></style></legend>

        如何在 JavaScript 中将 JSON 转换为 YAML

        时间:2023-09-07
        • <legend id='fYnnl'><style id='fYnnl'><dir id='fYnnl'><q id='fYnnl'></q></dir></style></legend>
          <i id='fYnnl'><tr id='fYnnl'><dt id='fYnnl'><q id='fYnnl'><span id='fYnnl'><b id='fYnnl'><form id='fYnnl'><ins id='fYnnl'></ins><ul id='fYnnl'></ul><sub id='fYnnl'></sub></form><legend id='fYnnl'></legend><bdo id='fYnnl'><pre id='fYnnl'><center id='fYnnl'></center></pre></bdo></b><th id='fYnnl'></th></span></q></dt></tr></i><div id='fYnnl'><tfoot id='fYnnl'></tfoot><dl id='fYnnl'><fieldset id='fYnnl'></fieldset></dl></div>

              <bdo id='fYnnl'></bdo><ul id='fYnnl'></ul>

                  <tbody id='fYnnl'></tbody>

              1. <small id='fYnnl'></small><noframes id='fYnnl'>

                  <tfoot id='fYnnl'></tfoot>
                  本文介绍了如何在 JavaScript 中将 JSON 转换为 YAML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

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

                  I want to convert a json string to yaml format in javascript.I am trying my hand on google from last two days didnt found any solution or libraries. There are answers available for java but not for javascript.

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

                  Suppose i have json string like this:

                  {
                    "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 中.

                  There is a online converter http://www.json2yaml.com/ , but how to convert to it in javascript.

                  推荐答案

                  可以使用yaml NPM包.

                  const YAML = require('yaml');
                  
                  const jsonObject = {
                      version: "1.0.0",
                      dependencies: {
                          yaml: "^1.10.0"
                      },
                      package: {
                          exclude: [ ".idea/**", ".gitignore" ]
                      }
                  }
                  
                  const doc = new YAML.Document();
                  doc.contents = jsonObject;
                  
                  console.log(doc.toString());
                  

                  输出

                  version: 1.0.0
                  dependencies:
                    yaml: ^1.10.0
                  package:
                    exclude:
                      - .idea/**
                      - .gitignore
                  

                  这篇关于如何在 JavaScript 中将 JSON 转换为 YAML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将 Emscripten 与 Fortran 一起使用:LAPACK 绑定 下一篇:在 Google 应用引擎 Python 中提供静态 html

                  相关文章

                  最新文章

                  1. <legend id='1IUuz'><style id='1IUuz'><dir id='1IUuz'><q id='1IUuz'></q></dir></style></legend><tfoot id='1IUuz'></tfoot>
                    1. <small id='1IUuz'></small><noframes id='1IUuz'>

                      <i id='1IUuz'><tr id='1IUuz'><dt id='1IUuz'><q id='1IUuz'><span id='1IUuz'><b id='1IUuz'><form id='1IUuz'><ins id='1IUuz'></ins><ul id='1IUuz'></ul><sub id='1IUuz'></sub></form><legend id='1IUuz'></legend><bdo id='1IUuz'><pre id='1IUuz'><center id='1IUuz'></center></pre></bdo></b><th id='1IUuz'></th></span></q></dt></tr></i><div id='1IUuz'><tfoot id='1IUuz'></tfoot><dl id='1IUuz'><fieldset id='1IUuz'></fieldset></dl></div>

                        <bdo id='1IUuz'></bdo><ul id='1IUuz'></ul>