YAML - JSON Schema



JSON schema in YAML is considered as the common denominator of most modern computer languages. It allows parsing JSON files. It is strongly recommended in YAML that other schemas should be considered on JSON schema. The primary reason for this is that it includes key value combination which are user friendly. The messages can be encoded as key and can be used as and when needed.

The JSON schema is scalar and lacks a value. A mapping entry in JSON schema is represented in the format of some key and value pair where null is treated as valid.

Example

A null JSON schema is represented as shown below −

!!null null: value for null key
key with null value: !!null null

The output of JSON representation is mentioned below −

{
   "null": "value for null key", 
   "key with null value": null
}

Example

The following example represents the Boolean JSON schema −

YAML is a superset of JSON: !!bool true
Pluto is a planet: !!bool false

The following is the output for the same in JSON format −

{
   "YAML is a superset of JSON": true, 
   "Pluto is a planet": false
}

Example

The following example represents the integer JSON schema −

negative: !!int -12
zero: !!int 0
positive: !!int 34
The output of integer generated JSON schema is shown below:
{
   "positive": 34, 
   "zero": 0, 
   "negative": -12
}

Example

The tags in JSON schema is represented with following example −

A null: null
Booleans: [ true, false ]
Integers: [ 0, -0, 3, -19 ]
Floats: [ 0., -0.0, 12e03, -2E+05 ]
Invalid: [ True, Null, 0o7, 0x3A, +12.3 ]

You can find the JSON Output as shown below −

{
   "Integers": [
      0, 
      0, 
      3, 
      -19
   ], 
   
   "Booleans": [
      true, 
      false
   ], 
   "A null": null, 

   "Invalid": [
         true, 
         null, 
         "0o7", 
         58, 
         12.300000000000001
   ], 
   
   "Floats": [
      0.0, 
      -0.0, 
      "12e03", 
      "-2E+05"
   ]
}
Advertisements