title: jsonSchema to validate conditionally required attributes
body: <p>My JSON payload contains two attributes <code>home_number</code>, <code>home_name</code> and <strong>at least one attribute always be required</strong>. Apart from that those attributes have the following additional constraints.</p>
  <blockquote>
  <p>home_number: type: string, Max length: 4</p>
  <p>home_name: type: string, Max length: 50</p>
  </blockquote>
  <p>JSON schema should throw an error <strong>if both attributes did not meet requirements</strong>.</p>
  <p>eg:</p>
  <p>valid JSON</p>
  <pre><code>{
      &quot;home_number&quot;: &quot;1234&quot;, // valid
  }
  </code></pre>
  <p>valid JSON</p>
  <pre><code>{
      &quot;home_number&quot;: null, // invalid
      &quot;home_name&quot;: &quot;test_home_name&quot; // valid
  }
  </code></pre>
  <p>invalid JSON</p>
  <pre><code>{
      &quot;home_number&quot;: &quot;12345&quot;, // invalid
      &quot;home_name&quot;: null // invalid
  }
  </code></pre>
  <p>I tried the following JSON schema with <code>draft-07</code> version using <strong>if, then</strong> keywords.</p>
  <pre><code>{
      &quot;$schema&quot;: &quot;http://json-schema.org/draft-07/schema#&quot;,
      &quot;type&quot;: &quot;object&quot;,
      &quot;properties&quot;: {
          &quot;address&quot;: {
              &quot;$ref&quot;: &quot;#/definitions/address&quot;,
              &quot;properties&quot;: {
                  &quot;house_number&quot;: {
                      &quot;$ref&quot;: &quot;#/definitions/address/house_number&quot;
                  },
                  &quot;house_name&quot;: {
                      &quot;$ref&quot;: &quot;#/definitions/address/house_name&quot;
                  },
                  &quot;post_code&quot;: {
                      &quot;$ref&quot;: &quot;#/definitions/address/postcode&quot;
                  }
              }
          }
      },
      &quot;required&quot;: [
          &quot;address&quot;
      ],
      &quot;definitions&quot;: {
          &quot;address&quot;: {
              &quot;type&quot;: &quot;object&quot;,
              &quot;properties&quot;: {
                  &quot;postcode&quot;: {
                      &quot;type&quot;: &quot;string&quot;,
                      &quot;maxLength&quot;: 6
                  }
              },
              &quot;anyOf&quot;: [
                  {
                      &quot;required&quot;: [
                          &quot;house_number&quot;
                      ]
                  },
                  {
                      &quot;required&quot;: [
                          &quot;house_name&quot;
                      ]
                  }
              ],
              &quot;if&quot;: {
                  &quot;properties&quot;: {
                      &quot;house_name&quot;: {
                          &quot;not&quot;: {
                              &quot;type&quot;: &quot;string&quot;,
                              &quot;maxLength&quot;: 50
                          }
                      }
                  }
              },
              &quot;then&quot;: {
                  &quot;properties&quot;: {
                      &quot;house_number&quot;: {
                          &quot;type&quot;: &quot;string&quot;,
                          &quot;maxLength&quot;: 4
                      }
                  }
              },
              &quot;required&quot;: [
                  &quot;postcode&quot;
              ]
          }
      }
  }
  </code></pre>
  <p>My question is is there any other/better approach to achieve this
  using <code>draft-04</code> version without using <code>draft-07</code> if then keywords?</p>