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]
Re: [xml-dev] Is JSON Schema simpler than XML Schema?



On Wed, Aug 1, 2018 at 9:36 AM, Costello, Roger L. <costello@mitre.org> wrote:

Hi Folks,

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


CSV is also simpler than XML. Whether or not that is  advantage of CSV depends on the context
 

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.


Aren't you overlooking the fact that one is not a accurate representation of the other because the JSON InternationalString doesn't have the extensible and inheritable semantics of the complex type you  are trying to mimic  and the XML model allows mixed content which the JSON model cannot accommodate.
 

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:


and you represented an atomic concept (the version XML atttribute) with a JSON object which allows it to have non-atomic content. 
 

"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.

 
The InternationalString  content model you are trying to replicate is a simple thing . 

 

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.


You may as well ask whether an apple is simpler than an orange.
 



[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