Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8697

Node.jsのnpmモジュールを使ってjsonファイルをminify・整形する手順

$
0
0

はじめに

Windows環境で、Node.jsのnpmモジュールを使って以下を行う手順をまとめます。

  • JSONファイルの軽量化(minify):改行やスペースの削除
  • JSONファイルの整形:改行やインデントにより見やすくする

使用モジュール

準備:モジュールのインストール

  1. Node.jsを取得しインストールする。→ https://nodejs.org/ja/

  2. Node.js command promptを起動する。

  3. 以下のコマンドを実行する。(2行目のプロキシ設定は必要な場合のみ実行)

$ npm -g config set registry http://registry.npmjs.org/
$ npm -g config set proxy http://xxx.xxx.xxx:8080
$ npm install -g json-minify
$ npm install -g format-jsonfile

使用方法

Node.js command promptから、以下のコマンドを実行する。

JSONファイルの軽量化

$ type test1.json
  [
    {
      "name": "foo",
      "age": 10
    },
    {
      "name": "bar",
      "age": 20
    },
    {
      "name": "hoge",
      "age": 30
    }
  ]
$ json-minify test1.json
  [{"name":"foo","age":10},{"name":"bar","age":20},{"name":"hoge","age":30}]

JSONファイルの整形

$ type test2.json
  [{"name":"foo","age":10},{"name":"bar","age":20},{"name":"hoge","age":30}]
$ format-jsonfile test2.json
  [
    {
      "name": "foo",
      "age": 10
    },
    {
      "name": "bar",
      "age": 20
    },
    {
      "name": "hoge",
      "age": 30
    }
  ]

参考記事


Viewing all articles
Browse latest Browse all 8697

Trending Articles