LoginSignup
6
6

More than 5 years have passed since last update.

schemizeのnode.js版作った

Posted at

shcemizeという、JSONからJSON Schemaを生成する便利なGemがある。

schemizeを使うためだけにGemfileを書くのが嫌だったので、node-schemizeを作った。

// とりあえずグローバルにインストール
$ npm install -g schemize

// デフォルト
$ echo '{ "key": "value" }' | schemize
{"type":"object","properties":{"key":{"type":"string"}}}

// プリチー
$ echo '{ "key": "value" }' | schemize --pretty
{
  "type": "object",
  "properties": {
    "key": {
      "type": "string"
    }
  }
}

// プリチーはインデント数と"tab"が指定可能
$ echo '{ "key": "value" }' | schemize --pretty tab
{
        "type": "object",
        "properties": {
                "key": {
                        "type": "string"
                }
        }
}

yamlはyaml屋ということで、yamlを出力したい場合はjs-yaml等を使ってください。

$ npm install -g js-yaml
$ echo '{ "key": "value" }' | schemize | js-yaml
type: object
properties:
  key:
    type: string

バグ等はissueにて頼む!

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