Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON schema draft4 VS JSON schema draft3

What are the features present in the schema draft 4 that are not in the JSON schema draft 3 produced by IETF ?

like image 529
user2430996 Avatar asked Jun 20 '13 04:06

user2430996


People also ask

What is the latest JSON Schema version?

The current version is 2020-12! The previous version was 2019-09.

What is JSON Schema draft 4?

Draft 4 defined a value for $schema without a specific dialect ( http://json-schema.org/schema# ) which meant, use the latest dialect. This has since been deprecated and should no longer be used. You might come across references to Draft 5. There is no Draft 5 release of JSON Schema.

What is the difference between JSON and JSON Schema?

JSON (JavaScript Object Notation) is a simple and lightweight text-based data format. JSON Schema is an IETF standard providing a format for what JSON data is required for a given application and how to interact with it.

How do I check if a JSON Schema is valid?

The simplest way to check if JSON is valid is to load the JSON into a JObject or JArray and then use the IsValid(JToken, JsonSchema) method with the JSON Schema. To get validation error messages, use the IsValid(JToken, JsonSchema, IList<String> ) or Validate(JToken, JsonSchema, ValidationEventHandler) overloads.


2 Answers

From the change logs:

New keywords

  • anyOf (match at least one schema in the schema array),
  • allOf (match all schemas in the schema array),
  • oneOf (match exactly one schema in the schema array),
  • not (do not match the schema),
  • multipleOf (replaces divisibleBy),
  • minProperties and maxProperties (the minimum and maximum number of members in an object instance),
  • definitions (standardized container for inlined subschemas).

Removed:

  • disallow
  • extends
  • divisbleBy

Changed in functionality:

Type

  • When the value is an array, schemas are no longer allowed as elements. Also, the array must have at least one element.

Before


{
    "type": [ "string", { "other": "schema" } ]
}

Now


{
   "anyOf": [
       { "type": "string" },
       { "other": "schema" }
    ]
}

Required

  • Before, it was an attribute of subschemas in properties. It is now a first level keyword playing the same role, and has a string array as an argument.

Before


{
    "properties": {
        "p": {
            "type": "string",
            "required": true
        },
        "q": {
            "type": "string",
            "required": true
        }
    }
}

Now


{
    "properties": {
        "p": { "type": "string" },
        "q": { "type": "string" }
    },
    "required": [ "p", "q" ]
}

Dependencies

  • A single string in a property dependency is no longer allowed, only arrays are allowed

Before


{
    "dependencies": { "a": "b" }
}

Now


{
    "dependencies": { "a": [ "b" ] }
}
like image 127
hunterc Avatar answered Oct 30 '22 14:10

hunterc


If you're interested in a deep dive, you can review a diff between the two drafts on the IETF site.

However, if you're looking for a simpler summary of changes, Geraint Luff and Francis Galiegue created a changelog page on the project's github wiki that lists the changes, additions, and removals.

like image 29
ezkl Avatar answered Oct 30 '22 13:10

ezkl