Does anybody know how to generate a JSON schema from a existing XML schema (XSD file)? Are there any tools available for this?
相关问题
- Jackson Deserialization not calling deserialize on
- Illegal to have multiple roots (start tag in epilo
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Easiest way to get json and parse it using JQuery
相关文章
- json_encode 没有把数组转为json
- Livy Server: return a dataframe as JSON?
- Creating XML Elements without namespace declaratio
- Get Attribute Value From Simple XML Using JQuery /
- Unexpected end of JSON input from an ajax call
- How do I do a nested list (array) of schema refere
- iconv() Vs. utf8_encode()
- Convert C# Object to Json Object
Disclaimer: I'm the author of jgeXml.
jgexml has Node.js based utility
xsd2json
which does a transformation between an XML schema (XSD) and a JSON schema file.As with other options, it's not a 1:1 conversion, and you may need to hand-edit the output to improve the JSON schema validation, but it has been used to represent a complex XML schema inside an OpenAPI (swagger) definition.
A sample of the purchaseorder.xsd given in another answer is rendered as:
JSON Schema is not intended to be feature equivalent with XML Schema. There are features in one but not in the other.
In general you can create a mapping from XML to JSON and back again, but that is not the case for XML schema and JSON schema.
That said, if you have mapped a XML file to JSON, it is quite possible to craft an JSON Schema that validates that JSON in nearly the same way that the XSD validates the XML. But it isn't a direct mapping. And it is not possible to guarantee that it will validate the JSON exactly the same as the XSD validates the XML.
For this reason, and unless the two specs are made to be 100% feature compatible, migrating a validation system from XML/XSD to JSON/JSON Schema will require human intervention.
True, but after turning json to xml with xmlspy, you can use trang application (http://www.thaiopensource.com/relaxng/trang.html) to create an xsd from xml file(s).
Copy your XML schema here & get the JSON schema code to the online tools which are available to generate JSON schema from XML schema.
Disclaimer: I am the author of Jsonix, a powerful open-source XML<->JSON JavaScript mapping library.
Today I've released the new version of the Jsonix Schema Compiler, with the new JSON Schema generation feature.
Let's take the Purchase Order schema for example. Here's a fragment:
You can compile this schema using the provided command-line tool:
The compiler generates Jsonix mappings as well the matching JSON Schema.
Here's what the result looks like (edited for brevity):
Now this JSON Schema is derived from the original XML Schema. It is not exactly 1:1 transformation, but very very close.
The generated JSON Schema matches the generatd Jsonix mappings. So if you use Jsonix for XML<->JSON conversion, you should be able to validate JSON with the generated JSON Schema. It also contains all the required metadata from the originating XML Schema (like element, attribute and type names).
Disclaimer: At the moment this is a new and experimental feature. There are certain known limitations and missing functionality. But I'm expecting this to manifest and mature very fast.
Links:
npm install
A year after this question was originally asked, JSON Schema remains an IETF draft document. As of this writing (18 October 2011) the working group is trying to get agreement on draft 4 of the specification. Although there are a few speculative validation implementations (see http://json-schema.org/), most tool vendors haven't invested much effort into tools that implement JSON Schema development, editing or conversion.