[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Is JSON Schema simpler than XML Schema?

  • From: Eliot Kimber <ekimber@contrext.com>
  • To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
  • Date: Wed, 01 Aug 2018 09:18:07 -0500

Re:  Is JSON Schema simpler than XML Schema?

Maybe RELAX NG would be a better fit for JSON validation?

 

I haven’t looked inside any RNG validators, but I would be surprised if it was not relatively easy to bind the RNG pattern matching logic to JSON structures instead of XML structures.

 

Or maybe a JSON-specific version of RELAX NG would make sense.

 

But I guess you would still hit the issue that there is no well-defined mapping between JSON name-value pairs and semantic structures analogous to elements and attributes, so the utility would be limited to “If a map has this key, then it’s contained values must match this pattern”, which might still have significant utility.

 

Cheers,

 

Eliot

 

--

Eliot Kimber

http://contrext.com

 

 

 

From: "Costello, Roger L." <costello@mitre.org>
Date: Wednesday, August 1, 2018 at 8:36 AM
To: "xml-dev@l..." <xml-dev@l...>
Subject: 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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.