LoginSignup
5
6

More than 5 years have passed since last update.

【Node.js】スプレッドシートからJSONファイルを生成するコマンドラインツール

Last updated at Posted at 2015-06-15

はじめに

google-spreadsheet-to-json」というものを使います。
このシンプルなコマンドラインツールは、Googleのスプレッドシートに書き込まれた内容をJSONファイルとしてエクスポートします。
スプレッドシートにちょいっと書き込んで、コマンド一発で出力できるので便利です。

スプレッドシートを用意して公開する

ss.png

spreadsheet 作成

1行目は タイトル行(JSON のキーに該当)
2行目以降は データ行

ウェブに公開

ファイル > ウェブに公開

公開されたURLから spreadsheet ID を抽出して控えておく

google-spreadsheet-to-json をインストール

npm install --save-dev google-spreadsheet-to-json

実行

あとは以下のコマンドを叩くだけ

gsjson **spreadsheet ID** data.json

「data.json」というファイルが生成されます。

data.json

[
  {
    "id": 1,
    "page": "トップページ",
    "url": "/index.html",
    "title": "ゴルゴ13|トップページ",
    "discription": "超一流のスナイパー(狙撃手)「ゴルゴ13」ことデューク東郷の活躍を描く",
    "template": "A"
  },
  {
    "id": 2,
    "page": "ゴルゴ13の実績",
    "url": "/case/index.html",
    "title": "ゴルゴ13の実績",
    "discription": "超一流のスナイパー(狙撃手)「ゴルゴ13」のこれまでの凄い仕事を紹介する",
    "template": "A"
  },
  {
    "id": 3,
    "page": " └新三大ゴルゴ13の物凄い仕事 ①",
    "url": "/case/case01.html",
    "title": "新三大ゴルゴ13の物凄い仕事 ①",
    "discription": "新三大ゴルゴ13の物凄い仕事 ①",
    "template": "B"
  },
  {
    "id": 4,
    "page": " └新三大ゴルゴ13の物凄い仕事 ②",
    "url": "/case/case02.html",
    "title": "新三大ゴルゴ13の物凄い仕事 ②",
    "discription": "新三大ゴルゴ13の物凄い仕事 ②",
    "template": "B"
  },
  {
    "id": 5,
    "page": " └新三大ゴルゴ13の物凄い仕事 ③",
    "url": "/case/case03.html",
    "title": "新三大ゴルゴ13の物凄い仕事 ③",
    "discription": "新三大ゴルゴ13の物凄い仕事 ③",
    "template": "B"
  },
  {
    "id": 6,
    "page": "ゴルゴ13への依頼方法",
    "url": "/request/index.html",
    "title": "ゴルゴ13への依頼方法",
    "discription": "ゴルゴ13への依頼方法を紹介する。",
    "template": "A"
  },
  {
    "id": 7,
    "page": "CIAとゴルゴ13",
    "url": "/cia/index.html",
    "title": "CIAとゴルゴ13",
    "discription": "CIAとゴルゴ13の関係を紹介する。",
    "template": "A"
  }
]


5
6
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
5
6