8
8

More than 5 years have passed since last update.

js-yamlでymlをjsonに変換しました。

Last updated at Posted at 2015-07-08

Jsonはコメント書けないなど不便なのでymlファイルからJsonを作成しました。この環境はNodeはインストール済みとします。

js-yamlをインストール

js-yamlのインストール
npm install -g js-yaml 

npm installします。

ymlファイルを準備

hoge.ymlのファイルを作成します。

hoge.ymlを作成
data:
  type: "array"
  id:
    type: "integer" #数値
  message:
    type: "string"
required:
  - data

ymlファイルの中味を適当に書きました。

js-yamlコマンドで変換

ymlをjsonに変換
js-yaml hoge.yml > hoge.json

hoge.jsonが出来上がりました。

hoge.json
{
  "data": {
    "type": "array",
    "id": {
      "type": "integer"
    },
    "message": {
      "type": "string"
    }
  },
  "required": [
    "data"
  ]
}

jsonを手書きはきついのでyml書くほうが楽だと思いました。

おまけ

ymlをjsonへウェブで変換する場合は http://yamltojson.com/ が楽でした。

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8