XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Is JSON Schema simpler than XML Schema?

Hi Folks,

One of the purported advantages of JSON Schema is that it is simpler than XML Schema.

After converting an XML Schema to JSON Schema, I am skeptical of such claims.

In a previous post, I invited suggestions for converting an xs:complexType with mixed content to an equivalent JSON Schema. After assessing several approaches, I arrived at a JSON Schema representation. I represented the following xs:complexType

<xs:complexType name="InternationalString" mixed="true">
   
<xs:choice minOccurs="0" maxOccurs="unbounded">
       
<xs:element name="bdo" type="bdoType" />
       
<xs:element name="bdi" type="bdiType" />
   
</xs:choice>
   
<xs:attribute name="direction" type="directionType" />
</xs:complexType>

 

with this JSON Schema:

"InternationalString": {
   
"type": "array",
   
"items": {
       
"anyOf": [
           
{
               
"type": "object",
               
"properties": {
                        
"$": {"type": "string"}
               
}
           
},
           
{
               
"type": "object",
                
"properties": {
                        
"bdo": {"$ref": "#/definitions/bdoType"}
               
}
           
},
           
{
               
"type": "object",
               
"properties": {
                        
"bdi": {"$ref": "#/definitions/bdiType"}
                
}
           
},
           
{
               
"type": "object",
               
"properties": {
                       
"@direction": {"$ref": "#/definitions/directionType"}
               
}
           
}
       
]
   
}
}

 

One could reasonably argue that the XML Schema representation is simpler. At the very least, it is shorter.

The XML Schema that I converted has a second xs:complexType which extends the above xs:complexType with an attribute:

<xs:complexType name="PedigreeStringType">
   
<xs:complexContent mixed="true">
       
<xs:extension base="InternationalString">
            <xs:attribute name="pedigree" type="xs:string" />
       
</xs:extension>
   
</xs:complexContent>
</xs:complexType>

 

I believe this xs:complexType cannot be represented in JSON Schema. (If that is not correct, please let me know). The best that one can do is to copy the JSON Schema definition of "InternationalString" and add the version attribute:

"PedigreeStringType": {
   
"type": "array",
   
"items": {
       
"anyOf": [
           
. . .  copy the InternationalString JSON Schema representation
           
{
               
"type": "object",
               
"properties": {
                       
"@pedigree": {"type": "string"}
               
}
           
}
       
]
   
}
}

 

As you know, the danger of copy-and-paste is that if the parent type (InternationalString) is changed, then I must ensure that the changes are also made wherever I did a copy-and-paste.

Summary: I think it is probably true that JSON Schema is simpler than XML Schema for simple things. But for complex things, such as expressing mixed content and creating type hierarchies, I think XML Schema is simpler and more powerful.

I welcome your comments.

/Roger

 



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS