JSON Schemaを使ってみる
やること
JSON Schemaで項目間のチェックをする。 例えば、field1が1の場合に、field2はAであることをチェックする。 JSON Schemaで表現すると以下のようになる。
{ "type": "object", "properties": { "field1": { "type": "string" }, "field2": { "type": "string" } }, "if": { "properties": { "field1": { "const": "1" } } }, "then": { "properties": { "field2": { "const": "A" } } } }
試した結果
- Ruby Gem
- https://www.jsonschemavalidator.net
- 期待通り。