Unclear about the meaning of propertyNames

json schema propertynames example
json schema map
json schema required one of
json schema default value
json schema additionalproperties
json schema oneof
json schema enum of objects
json schema validator

Here is a JSON schema that uses propertyNames:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "propertyNames": {"enum": ["num", "name"]}
}

I "think" the meaning of that schema is this: A conforming JSON instance must be an object and the object must contain a "num" property and a "name" property; the value of the two properties is unspecified. Is that correct, is that what the schema means?

I created this instance:

{
   "num": 10
}

I validated that instance against the schema and the validator says it is valid. Hmm, why? Doesn't the schema specify that the object must contain both "num" and "name"?

propertyNames is a schema that all of an object's properties must be valid against. Let's take a look at less confusing example.

{
  "type": "object",
  "propertyNames": { "maxLength": 3, "minLength": 3 },
  "patternProperties": {
    "": { "type": "number" }
  }
}

This describes an object where all properties names must be of length 3 and all property values must be numbers. Here's an example.

{
  "usd": 1,
  "eur": 0.86815,
  "gbp": 0.76504,
  "cad": "1.31004",  <= Invalid property value
  "xx": 1.11         <= Invalid property name
}

Going back to your example, there is one property, "num", which valid against the propertyNames schema { "enum": ["num", "name"] }. Therefore, the value in your example is valid.

jsonschema - Unclear about the meaning of propertyNames, propertyNames is a schema that all of an object's properties must be valid against. Let's take a look at less confusing example. { "type": "object"  The java.util.Properties.propertyNames() method Returns an enumeration of all the keys in this property list, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list. Declaration. Following is the declaration for java.util.Properties.propertyNames() method

I'm not familiar with the schema approach taken by json-schema and find it quite confusing whether examples are definitions or implementations. However, my interpretation would be that property names are defined by an enumeration, which can either be a list of numbers

"propertyNames": {"enum": [1,2,3,4]}

or a list of names

"propertyNames": {"enum": ["Ellen","Sue","James","Tim"]}

an outside bet (which I doubt) would be that it should be:

"propertyNames": {"enum": [1, "Ellen", 2, "Sue", 3, "James", 4, "Tim"]}

The only scenario in which I can see your example being valid is if the word "enum" is intended to be replaced by the type of enum and that where an enum can have only one value that you needn't use an array but that equally valid should then be: {"num": [8,9,10]} and {"name": ["Ellen","Sue","James","Tim"]}

Apologies if this isn't the clear answer you were hoping for but I hope it might help trigger a solution.

Design pattern: Using "propertyNames" to catch unexpected , The following description is not the most concise and confused at least one person on the old issue, so it's worth discussing some here to find a  27 synonyms of unclear from the Merriam-Webster Thesaurus, plus 52 related words, definitions, and antonyms. Find another word for unclear. Unclear: not expressed in precise terms. Synonyms: fuzzy, indefinite, inexplicit… Antonyms: clear, definite, expl

Try this:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "required": ["num", "name"]
}

you can also specify the type of the properties like this:

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "required": ["num", "name"]
    "properties": {
        "num": {"type": "number"},
        "name": {"type": "string"}
    }
}

For more information, you can visit this link: https://json-schema.org/understanding-json-schema/reference/object.html

object, Properties; Required Properties; Property names; Size; Dependencies Try not to be confused by the two uses of the word "object" here: Python uses the word  A collection of baby names with meaning of unclear. We found in our database 35 names have the similar meanings. If you want to hold this word 'Unclear' for your lovely kid, please proceed to collection and choose any of the alternative in the list given below:

The Tithe Maps of England and Wales: A Cartographic Analysis and , A Cartographic Analysis and County-by-County Catalogue Roger Kain, Roger chns; hill-drawing, woods, parkland, building names, property names, churchyard​, moss, undivided common, disputed property; meaning of colouring is unclear. Fun Facts about the name Unclear. How unique is the name Unclear? Out of 6,028,151 records in the U.S. Social Security Administration public data, the first name Unclear was not present. It is possible the name you are searching has less than five occurrences per year. Weird things about the name Unclear: Your name in reverse order is Raelcnu.

JSON Schema Draft-06 Release Notes, "id", replaced by "$id", no longer easily confused with instance properties named "id" "type", definition of "integer", in draft-04, "integer" is listed as a primitive type "propertyNames", added, takes a schema which validates the names of all  Unclear definition is - not clear: such as. How to use unclear in a sentence.

CSS Pocket Reference: Visual Presentation for the Web, Keywords are defined on a per-property basis and have a meaning specific only to a given Keywords, like property names, are not case-sensitive. The status and application of initial is unclear as of this writing and may be unreliable. unclear definition: 1. not obvious or easy to see or know: 2. If you are unclear about something, you are not certain…. Learn more.

Comments
  • enum just indicates a list of values that are allowed, but doesn't mean that both are mandatory.
  • Ah! Thank you @D. Mayen. So, how would the schema specify that both "num" and "name" must be used in instance documents?
  • The "Understanding JSON Schema" site is becoming the De Facto source of understanding for JSON Schema authors. We appreciate that reading the actual specification document itself can be daunting. We are happy to help you understand it if you have further questions. Please feel free to join the official JSON Schema slack using the "Discussion" link on json-schema.org
  • Excellent! Thank you @Jason Desrosiers
  • Hello @D. Mayen I understand that approach. However, my intent is to learn what the new keyword "propertyNames" means and how to use it meaningfully.