@@ -99,6 +99,10 @@ updated to conform to the new rules.
9999 declared type. It's a more compact alternative to objects where the
100100 property names are replaced by the position in the tuple. Arrays or maps
101101 of tuples are especially useful for time-series data.
102+ - ** Choice:** A discriminated union of types, where one of the types is
103+ selected based on a discriminator property. The ` choice ` keyword is used
104+ to define the union and the ` selector ` property is used to specify the
105+ discriminator property.
102106- ** Namespaces:** Namespaces are a formal part of the schema language, allowing
103107 for more modular and deterministic schema definitions. Namespaces are used to
104108 scope type definitions.
@@ -610,6 +614,107 @@ elements. The schema above would match the following instance data:
610614[" apple" , " banana" , " cherry" ]
611615```
612616
617+ ### 4.6. Example: Declaring Tuples
618+
619+ Tuples are fixed-length arrays with named elements, declared via the ` tuple ` keyword.
620+
621+ ``` json
622+ {
623+ "$schema" : " https://json-structure.org/meta/core/v0/#" ,
624+ "type" : " tuple" ,
625+ "name" : " PersonTuple" ,
626+ "properties" : {
627+ "firstName" : { "type" : " string" },
628+ "age" : { "type" : " int32" }
629+ },
630+ "tuple" : [" firstName" , " age" ]
631+ }
632+ ```
633+
634+ An instance of this tuple type:
635+
636+ ``` json
637+ [" Alice" , 30 ]
638+ ```
639+
640+ ### 4.7. Example: Declaring Choice Types
641+
642+ Choice types define discriminated unions via the ` choice ` keyword. Two forms are supported:
643+
644+ #### Tagged Unions
645+
646+ Tagged unions represent the selected type as a single-property object:
647+
648+ ``` json
649+ {
650+ "$schema" : " https://json-structure.org/meta/core/v0/#" ,
651+ "type" : " choice" ,
652+ "name" : " StringOrNumber" ,
653+ "choices" : {
654+ "string" : { "type" : " string" },
655+ "int32" : { "type" : " int32" }
656+ }
657+ }
658+ ```
659+
660+ Valid instances:
661+
662+ ``` json
663+ { "string" : " Hello" }
664+ { "int32" : 42 }
665+ ```
666+
667+ #### Inline Unions
668+
669+ Inline unions extend a common abstract base type and use a selector property:
670+
671+ ``` json
672+ {
673+ "$schema" : " https://json-structure.org/meta/core/v0/#" ,
674+ "type" : " choice" ,
675+ "name" : " AddressChoice" ,
676+ "$extends" : " #/definitions/Address" ,
677+ "selector" : " addressType" ,
678+ "choices" : {
679+ "StreetAddress" : { "$ref" : " #/definitions/StreetAddress" },
680+ "PostOfficeBoxAddress" : { "$ref" : " #/definitions/PostOfficeBoxAddress" }
681+ },
682+ "definitions" : {
683+ "Address" : {
684+ "abstract" : true ,
685+ "type" : " object" ,
686+ "properties" : {
687+ "city" : { "type" : " string" },
688+ "state" :{ "type" : " string" },
689+ "zip" : { "type" : " string" }
690+ }
691+ },
692+ "StreetAddress" : {
693+ "type" : " object" ,
694+ "$extends" : " #/definitions/Address" ,
695+ "properties" : { "street" : { "type" : " string" } }
696+ },
697+ "PostOfficeBoxAddress" : {
698+ "type" : " object" ,
699+ "$extends" : " #/definitions/Address" ,
700+ "properties" : { "poBox" : { "type" : " string" } }
701+ }
702+ }
703+ }
704+ ```
705+
706+ Instance of this inline union:
707+
708+ ``` json
709+ {
710+ "addressType" : " StreetAddress" ,
711+ "street" : " 123 Main St" ,
712+ "city" : " AnyCity" ,
713+ "state" : " AS" ,
714+ "zip" : " 11111"
715+ }
716+ ```
717+
613718## 5. Using Companion Specifications
614719
615720The JSON Structure Core specification is designed to be extensible through
0 commit comments