fnogatz / xsd2json

Translate XML Schema into equivalent JSON Schema
MIT License
150 stars 28 forks source link

Json schema output have a '|:' string in the console #2

Closed developerworks closed 10 years ago

developerworks commented 10 years ago

Why there is an extra |: string in the most begining of json schema output, my xml schema is:

<!-- filename: models.xsd-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="models">
        <xs:complexType>
            <xs:all>
                <xs:element name="User" type="User" minOccurs="0"/>
                <xs:element name="Device" type="Device" minOccurs="0"/>
                <xs:element name="Ad" type="Ad" minOccurs="0"/>
            </xs:all>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="User">
        <xs:sequence>
            <xs:element name="id" type="xs:nonNegativeInteger"/>
            <xs:element name="name" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Device">
        <xs:sequence>
            <xs:element name="id" type="xs:nonNegativeInteger"/>
            <xs:element name="name" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Ad">
        <xs:sequence>
            <xs:element name="id" type="xs:nonNegativeInteger"/>
            <xs:element name="name" type="xs:string"/>
            <xs:element name="user_id" type="xs:nonNegativeInteger"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

and with the following command line:

swipl --quiet --nodebug -g 'main,halt' -s lib/cli.pl -- < test/xsd/models.xsd

The output is:

|:  {
  "definitions": {
    "User": {
      "required": ["id", "name" ],
      "type":"object",
      "properties": {
    "id": {"type":"integer", "minimum":0, "exclusiveMinimum":false},
    "name": {"type":"string"}
      }
    },
    "Device": {
      "required": ["id", "name" ],
      "type":"object",
      "properties": {
    "id": {"type":"integer", "minimum":0, "exclusiveMinimum":false},
    "name": {"type":"string"}
      }
    },
    "Ad": {
      "required": ["id", "name", "user_id" ],
      "type":"object",
      "properties": {
    "id": {"type":"integer", "minimum":0, "exclusiveMinimum":false},
    "name": {"type":"string"},
    "user_id": {"type":"integer", "minimum":0, "exclusiveMinimum":false}
      }
    }
  }
}
fnogatz commented 10 years ago

The |: is created by using stream(user_input) of SWI-Prolog. Since the normal use case would be to pipe the output of xsd2json or write it into a file, this should be no problem. For example you could simply call

swipl -q -f cli.pl -- < /path/to/your.xsd > output.json

(with the latest version) so that the output.json should not contain the |:.

developerworks commented 10 years ago

Thank you so much, the xsd2json is very useful for me , thanks your efforts.