npmモジュールでJSONをYAMLに変換(CLI)
JSONをYAMLに変換する(json2yaml)
JSONをYAMLに変換するjson2yamlモジュールをインストールします。
sample.json
{
"data": {
"type": "array",
"id": {
"type": "integer"
},
"message": {
"type": "string"
}
},
"required": [
"id",
"message"
]
}
json2yamlをインストールします。
$ npm install json2yaml
sample.jsonをyaml形式に変更します。
$ npx json2yaml sample.json
---
data:
type: "array"
id:
type: "integer"
message:
type: "string"
required:
- "id"
- "message"
ファイルにリダイレクトしたい場合は以下のように>を使います。
$ npx json2yaml sample.json > out.yaml
JSONをYAMLに変換する(js-yaml)
JSONをYAMLに変換するjs-yamlモジュールをインストールします。
$ npm install js-yaml
YAMLをJSONに変換します。
$ npx js-yaml sample.json
data:
type: array
id:
type: integer
message:
type: string
required:
- id
- message
js-yamlの方がきれいです。
また、js-yamlは引数をymlファイルにすればJSON形式に変換してくれます。
$ npx js-yaml sample.yml
{
"data": {
"type": "array",
"id": {
"type": "integer"
},
"message": {
"type": "string"
}
},
"required": [
"id",
"message"
]
}

KHI入社して退社。今はCONFRAGEで正社員です。関西で140-170/80~120万から受け付けております^^
得意技はJS(ES20xx),Java,AWSの大体のリソースです
コメントはやさしくお願いいたします^^
座右の銘は、「狭き門より入れ」「願わくは、我に七難八苦を与えたまえ」です^^

コメント