title: JSON Schema: validate a number-or-null value
body: <p>Is there a way to enable a JSON schema property to be either a number or <code>null</code>?</p>
  
  <p>I am building an API which contains a <code>heading</code> attribute. Can be a number between 0 (inclusive) and 360 (exclusive), or null, so the following inputs are OK:</p>
  
  <pre class="lang-json prettyprint-override"><code>{"heading": 5}
  {"heading": 0}
  {"heading": null}
  {"heading": 12}
  {"heading": 120}
  {"heading": null}
  </code></pre>
  
  <p>And the following inputs are erroneous:</p>
  
  <pre class="lang-json prettyprint-override"><code>{"heading": 360}
  {"heading": 360.1}
  {"heading": -5}
  {"heading": false}
  {"heading": "X"}
  {"heading": 1200}
  {"heading": false}
  </code></pre>
  
  <p><strong>Addendum:</strong></p>
  
  <p><code>anyOf</code> is clearly the right answer. Adding the full schema for clarity.</p>
  
  <h3>Schema</h3>
  
  <pre><code>{
      "$schema": "http://json-schema.org/draft-04/schema#",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "heading": {
          "anyOf": [
            {"type": "number"},
            {"type": "null"}
          ]
        }
      }
  }
  </code></pre>