Ped*_*xto 6 javascript json yaml
我有这个yaml文件:
description:
is_a: AnnotationProperty
labelEN: description
labelPT: descrição
relevance:
is_a: AnnotationProperty
domain: Indicator
labelEN: relevance
labelPT: relevância
title:
is_a: AnnotationProperty
labelPT: título
labelEN: title
range: Literal
Run Code Online (Sandbox Code Playgroud)
我需要将它转换为json,所以我可以得到这样的东西:
{
"description": {
"is_a": "AnnotationProperty",
"labelEN": "description",
"labelPT": "descrição"
},
"relevance": {
"is_a": "AnnotationProperty",
"domain": "Indicator",
"labelEN": "relevance",
"labelPT": "relevância"
},
"title": {
"is_a": "AnnotationProperty",
"labelPT": "título",
"labelEN": "title",
"range": "Literal"
}
}
Run Code Online (Sandbox Code Playgroud)
并将其保存在js变量中...
那么,我该怎么做呢?
小智 13
您可以使用在节点上运行的简单javascript脚本来解决这个问题.
js-yaml包:npm install js-yaml -g然后将此脚本保存到文件中,并使用node.js运行它:
var inputfile = 'input.yml',
outputfile = 'output.json',
yaml = require('js-yaml'),
fs = require('fs'),
obj = yaml.load(fs.readFileSync(inputfile, {encoding: 'utf-8'}));
// this code if you want to save
fs.writeFileSync(outputfile, JSON.stringify(obj, null, 2));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12926 次 |
| 最近记录: |