Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agree, either you choose the <code>object</code> or <code>string</code> type. I have looked into the <a href="http://json-schema.org/documentation.html" rel="noreferrer">JSON Schema documentation</a> and I could not find anything to express the constraint as clear as needed. Hence, a short discussions of the two approaches there are to my mind.</p> <p><strong>Type String</strong></p> <p>JSON Schema defines seven primitive types, including object. A string is simply defined as a JSON string. The RFC 4627 defines a JSON string as follows</p> <blockquote> <blockquote> <p>A string is a sequence of zero or more Unicode characters</p> </blockquote> </blockquote> <p>This would apply to your case, even though the content of the string has to be restricted. The question is how to communicate the restriction. I would use a <code>description</code> to reference to another subschema. You can even define a <code>pattern</code> for the string an encode the subschema as regular expression. This, however, will be very error prone and not human readable at all. It could, however, be used for better schema validation of the data.</p> <pre><code>{ "title": "My Schema", "type": "object", "properties": { "A": { "type": "string". "description": "Please refer to http://... for the subschema." }, "B": { "type": "string" "description": "Please refer to http://... for the subschema." } } </code></pre> <p>This has the advantage, that it is unmistakably clear that the JSON provider has to put a string into that property. The disadvantage is that the complete schema cannot be viewed as once, the description might be overseen and it is also cumbersome in the look up process. In the end it will be very confusing when seeing type <code>string</code> but a <code>object</code> is defined in the subschema.</p> <p><strong>Type Object</strong></p> <p>By using simply the type as it is you avoid all the disadvantages of using a string. The problem here really is that the description stating that is has to be a string encoding will be overlooked.</p> <pre><code>{ "title": "My Schema", "type": "object", "properties": { "A": { "description": "Must be encoded as string", "type": "object", "properties": { "A1": { "type": "string" }, "A2": { "type": "string" } } }, "B": { "description": "Must be encoded as string", "type": "object" "properties": { "A1": { "type": "string" }, "A2": { "type": "string" } } } } </code></pre> <p>You can always make something completely bogus, like using the type <code>string</code> and defining <code>properties</code> for it, but this will be invalid JSON Schema.</p> <hr> <p>I would recommend you to use the <strong>Type Object</strong> approach. While there is this constraint using the string type will always lead to degrading the data behind it. Constraints can be enforced in other ways to. Watch who provides the data, communicate the constraint to all parties, block data that is not valid with respect to this constraint etc.</p> <p>And who knows, maybe this constraint will not there forever and if that changes, you would need to change the schema again in the other case you only would need to drop the comment stating the requirement of string encoding.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload