4

Of course XML and JSON are different. But if you see these formats on the level of pure structure they might be exchangeable representations for the same data. Both can be described with schema definitions: JSON Schema and XML Schema.

Can you describe the same data structures with JSON Schema as you can describe with XML Schema and vise versa? Is it possible to write JSSD/XSD converters that don't loose information while converting?

Sebastian Barth
  • 4,079
  • 7
  • 40
  • 59
  • I committed the mentioned project to github now: https://github.com/redaktor/owl2jsonschema.js - for now XML Schema conversion is just a small subpart but I am working on xsd constraints now. This file might be of particular interest: https://github.com/redaktor/owl2jsonschema.js/blob/master/lib/hardcoded-schemas.json - it contains the predefined xsd datatypes. – sebilasse Feb 04 '15 at 16:13
  • I wrote a tool to convert XML Schemas into JSON Schemas, pleace check this anwer: http://stackoverflow.com/a/30006975/303810 – lexicore Aug 26 '15 at 13:05

2 Answers2

3

I'm pretty sure the answer is yes in a while.

Using current JSON Schema draft 04 (hyperschema) you can currently map the most of XML Schema to JSON Schema. There are some ugly workarounds which will be obsolete with draft 05: I am pretty sure that the proposals propertyLinks will "make it" into the next draft, see this page: https://github.com/json-schema/json-schema/wiki/v5-Proposals

There are also existing projects, e.g. owl2vowl and webowl is using a to JSON Schema converter. It is Java. I am not sure how far the XML Schema support is. However:

I began writing a JSON Schema "playground" in javascript (with an optional 'node.js part'). In javascript there is a solution for schema.org. And I asked myself how to import OWL / RDFS / XML Schema in a similar manner. I am 70% ready with the OWL / RDFS part now.

So if your interested in this, we could setup a discussion for the XML Schema part and I could push to github before.

sebilasse
  • 4,278
  • 2
  • 37
  • 36
2

I'm pretty sure the answer is no.

Firstly, it's quite hard to define a completely lossless mapping between JSON and XML at the instance level even before you start thinking about schemas. So the concept of "the same data structures" needs qualification.

Much of XML Schema is concerned with grammars and content models, for example saying that a section consists of an optional heading followed by zero or more paragraphs, each of which can be a p, ul, or table element. I don't think there's anything remotely like that in JSON Schema. Arrays in JSON Schema seem to be treated as uniform and homogenous.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • 3
    I'm not sure about the correctness of your premise. XML is nothing else than a treelike structure and so is JSON. The only things in XML that don't exist in JSON are namespaces and the specification of attributes. Both can be mapped to JSON (e.g. using qualifiers for attributes like `$attribute` as well as strings instead of namespace notation like `"p-parameter": CONTENT` instead of ` CONTENT `). When talking about schema description it might be a different thing because here we don't see structure, but semantic. – Sebastian Barth Oct 07 '14 at 15:26
  • 2
    I find it ironic that JavaScript is giving rise to Type-Safe variants (e.g. TypeScript) and now, finally, JSON schemas are emerging to solve the serialization/deserialization problem where 'grammar', domain integrity and type safety make a difference. We all agree an XML document that has not been validated against a strict schema is easily replaced by a lean (not fat) JSON document. Schemas assert whether a "1" is a number (floating or integral) or is a string; and in some cases that is important to know. – subsci Jul 07 '15 at 07:28