1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JSON Schemaでプロパティ名にキーワード(typeとかidとか)が指定されている場合の記述方法

Posted at

結論

結論だけ先に書くと「気にせず書いてしまえばOK」(実装にもよるのかもしれないけど)。

背景

JSON Schemaで検証しようと思った時にこんなJSONがあったとします。

 {
   "foobar": {
      "type": "hogehoge"
   }
 }

その時にJSON Schemaでfoobar.typeを検証する時に

{
  "id": "/foobar",
  "type": "object",
  "properties": {
    "foobar": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string"
        }
      },
      "additionalProperties": false
    }
  }
}

なんて書いてしまって大丈夫なのか?とか思ってしまったのですが、特に問題無いようです。

実装にもよるかもしれませんが、npmのjsonschemaでは正常に動きました。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?