1

The objective is to convert an XSD schema to JSON Schema. I am first trying to XSD to JSON and then see if i can fix the JSON to become JSON Schema.All this procedure is because right now i don't know a direct way of converting XSD to JSON Schema. Consider the following fragment for now. i have the following fragment of XSD

<attributeGroup name="SimpleObjectAttributeGroup">
    <attribute ref="s:id"/>
    <attribute ref="s:metadata"/>
    <attribute ref="s:linkMetadata"/>
  </attributeGroup>

The corresponding JSON i get is

 "attributeGroup": {
      "name": "SimpleObjectAttributeGroup",
      "attribute": [
        {
          "ref": "s:id"
        },
        {
          "ref": "s:metadata"
        },
        {
          "ref": "s:linkMetadata"
        }
      ]
    }

So my question is

  1. is this right ?
  2. Should i override the attribue ref as $ref instead of @ref (but that would make de serialization tough )
  3. Is this conforming to the JSONSchema specification.

The specification can be found at http://json-schema.org/

i used c# and Json.net to achieve this.

ashutosh raina
  • 9,228
  • 12
  • 44
  • 80
  • 1
    If you're looking for a direct way of converting an XSD to a JSON schema, you could look at this question: http://stackoverflow.com/questions/3922026/generate-json-schema-from-xml-schema-xsd – NT3RP Nov 16 '11 at 17:29
  • it does not do what i want it to do , i have looked at it in depth for weeks .. – ashutosh raina Nov 16 '11 at 17:30
  • i asked this question http://stackoverflow.com/questions/8063811/maintain-directory-hierarchy-when-converting-from-xsd-to-java-class , one of the many problems i faced while doing what your idea asks me to do . – ashutosh raina Nov 16 '11 at 17:31
  • 1
    Just a quick note, the JSON isn't valid JSON, there should be brackets {} around the whole thing to make it a JSON object. – CLo Nov 18 '11 at 19:50
  • chris ...i have just posted a small fragment of the entire json , i do have {} surrounding the entire thing..i have not pasted the entire thing due to space constraints – ashutosh raina Nov 19 '11 at 05:46
  • You cannot have been reading the specification (draft 3) you are referring to to begin with. There is a clear example in it how a JSON Schema must look, and your output does not remotely look like it. There is no `attribute` and no `@` in the example, for example; there is a `properties` attribute (or property, if converted to an ECMAScript `Object`). – PointedEars Nov 19 '11 at 12:14
  • @PointedEars can u tell me what the right JSONSchema would be ? all guidance is appreciated .. – ashutosh raina Nov 23 '11 at 18:59
  • Read sections 3 to 6 of the draft you have been referring to. – PointedEars Nov 23 '11 at 20:51

1 Answers1

1
     "SimpleObjectAttributeGroup": {          
            {
              "id":{
                     "type":"sometype"
properties of id go here 
                    }
            },
          ....and more properties 
         }
This seems to be the correct JOSNSchema.
ashutosh raina
  • 9,228
  • 12
  • 44
  • 80