Loading ...
Sorry, an error occurred while loading the content.

SV: [json] JSON representation for XML snippet

Expand Messages
  • Jakob Kruse
    ”instead of the standard, there however multiple competing standard proposals […] that do allow converting any XML content into well-formed […]
    Message 1 of 28 , Sep 14, 2009
    • 0 Attachment
      ”instead of "the" standard, there however multiple competing standard proposals […] that do allow converting any XML content into well-formed […] JSON.”

      I don’t think that’s true, and it is certainly not true for Badgerfish. All of the mapping conventions I know of fail to correctly represent “document type” XML such as:

      <asdf>
      <a>…</a>
      <a>…</a>
      <b>…</b>
      <a>…</a>
      </asdf>

      This speaks to the heart of the difference between XML and JSON. In order to represent something like this in JSON, the contents of the “asdf” element would have to be in an array. This is not an impossible solution, but using that convention throughout makes for very ugly JSON.

      /Jakob

      Fra: json@yahoogroups.com [mailto:json@yahoogroups.com] På vegne af Tatu Saloranta
      Sendt: 14. september 2009 18:51
      Til: json@yahoogroups.com
      Emne: Re: [json] JSON representation for XML snippet


      On Mon, Sep 14, 2009 at 9:17 AM, Shalab Goel <goel.shalab@...> wrote:
      > Hello,
      >
      > Is there a standard way to represent the information in following XML snippet
      > as JSON output.
      >
      > <attributes>
      > <attribute a1="v1">value1</attribute>
      > <attribute a2="v2">value2</attribute>
      > </attributes>
      >
      > Is there an online tool that would generate this conversion?

      It depends on what you'd expect to get out of it, but I think the
      answer is no: there is nothing obvious and standard.
      It really depends on meaning of data above.

      <rant>
      personally I think it is better to convert from original data
      (objects, relational data) into structurally distinct data formats
      (xml and json have fundamentally differen data models, hierachic vs
      struct/frame/object model... but I digress). And as such, if possible,
      it's better to figure out meaning of data and then produce "native"
      xml and json, without trying to convert from json to xml or vice
      versa. Latter is more difficult, and data in one (... or both) of
      formats will end up looking funny and somewhat unreadable
      </rant>

      Anyway: instead of "the" standard, there however multiple competing
      standard proposals (called "mapping conventions") that do allow
      converting any XML content into well-formed (if bit odd-looking and
      alien-feeling :) ) JSON.
      One such convention is Badgerfish (see, for example
      [http://sujitpal.blogspot.com/2007/10/converting-xml-to-badgerfish-json.html%5d);
      and there are multiple others that claim to produce natural JSON.

      -+ Tatu +-

      [Non-text portions of this message have been removed]
    • Mark Joseph
      To do the XML to JSON conversion I use our XSLT (which can also go the other way as well)
      Message 2 of 28 , Sep 14, 2009
      • 0 Attachment
        To do the XML to JSON conversion I use our XSLT (which can also go the other way as well)

        <xsl:output method=’json’/>
        https://www.p6r.com/articles/2008/11/02/xsloutput-methodjson/




        Mark Joseph, Ph.D.
        President
        P6R, Inc
        408-205-0361
        mark@...
        Skype: markjoseph_sc
        _____

        From: Jakob Kruse [mailto:kruse@...]
        To: json@yahoogroups.com
        Sent: Mon, 14 Sep 2009 10:38:56 -0700
        Subject: SV: [json] JSON representation for XML snippet






        ”instead of "the" standard, there however multiple competing standard proposals […] that do allow converting any XML content into well-formed […] JSON.”

        I don’t think that’s true, and it is certainly not true for Badgerfish. All of the mapping conventions I know of fail to correctly represent “document type” XML such as:

        <asdf>
        <a>…</a>
        <a>…</a>
        <b>…</b>
        <a>…</a>
        </asdf>

        This speaks to the heart of the difference between XML and JSON. In order to represent something like this in JSON, the contents of the “asdf” element would have to be in an array. This is not an impossible solution, but using that convention throughout makes for very ugly JSON.

        /Jakob

        Fra: json@yahoogroups.com [mailto:json@yahoogroups.com] På vegne af Tatu Saloranta
        Sendt: 14. september 2009 18:51
        Til: json@yahoogroups.com
        Emne: Re: [json] JSON representation for XML snippet


        On Mon, Sep 14, 2009 at 9:17 AM, Shalab Goel <goel.shalab@...> wrote:
        > Hello,
        >
        > Is there a standard way to represent the information in following XML snippet
        > as JSON output.
        >
        > <attributes>
        > <attribute a1="v1">value1</attribute>
        > <attribute a2="v2">value2</attribute>
        > </attributes>
        >
        > Is there an online tool that would generate this conversion?

        It depends on what you'd expect to get out of it, but I think the
        answer is no: there is nothing obvious and standard.
        It really depends on meaning of data above.

        <rant>
        personally I think it is better to convert from original data
        (objects, relational data) into structurally distinct data formats
        (xml and json have fundamentally differen data models, hierachic vs
        struct/frame/object model... but I digress). And as such, if possible,
        it's better to figure out meaning of data and then produce "native"
        xml and json, without trying to convert from json to xml or vice
        versa. Latter is more difficult, and data in one (... or both) of
        formats will end up looking funny and somewhat unreadable
        </rant>

        Anyway: instead of "the" standard, there however multiple competing
        standard proposals (called "mapping conventions") that do allow
        converting any XML content into well-formed (if bit odd-looking and
        alien-feeling :) ) JSON.
        One such convention is Badgerfish (see, for example
        [http://sujitpal.blogspot.com/2007/10/converting-xml-to-badgerfish-json.html%5d);
        and there are multiple others that claim to produce natural JSON.

        -+ Tatu +-

        [Non-text portions of this message have been removed]




        [Non-text portions of this message have been removed]
      • Andrea Giammarchi
        er, me too in the precedent link there is a demo: http://www.3site.eu/JXON/ I guess my spec is simple: Boolean = true|false Date =
        Message 3 of 28 , Sep 14, 2009
        • 0 Attachment
          er, me too in the precedent link there is a demo:
          http://www.3site.eu/JXON/

          I guess my spec is simple:

          <element>
          Boolean = <boolean>true|false</boolean>
          Date = <date>YYYY-MM-DDTHH:II:SS</date>
          Null = <null/>
          Number = <number>N|Z</number>
          String = <string>string content</string>
          Array = <array><element-list/></array>
          Object = <object><element-list key="element-key"/></object>

          <element-list> = a list of precedent element

          While the code to transform to and from XML to JSON and vice-versa is here:
          http://www.devpro.it/code/193.html

          A bit old, I need to rewrite some stuff, but maybe examples and the
          code itself could be a hint.

          Regards




          On Mon, Sep 14, 2009 at 7:17 PM, Mark Joseph <mark@...> wrote:

          >
          >
          > To do the XML to JSON conversion I use our XSLT (which can also go the
          > other way as well)
          >
          > <xsl:output method=�json�/>
          > https://www.p6r.com/articles/2008/11/02/xsloutput-methodjson/
          >
          > Mark Joseph, Ph.D.
          > President
          > P6R, Inc
          > 408-205-0361
          > mark@... <mark%40p6r.com>
          > Skype: markjoseph_sc
          > _____
          >


          [Non-text portions of this message have been removed]
        • Tatu Saloranta
          ... Perhaps I should have worded it as try to allow... . And that they do it with varying level of success -- as you point out, badgerfish fails for that
          Message 4 of 28 , Sep 14, 2009
          • 0 Attachment
            On Mon, Sep 14, 2009 at 10:38 AM, Jakob Kruse <kruse@...> wrote:
            > ”instead of "the" standard, there however multiple competing standard proposals […] that do allow converting any XML content into well-formed […] JSON.”
            >
            > I don’t think that’s true, and it is certainly not true for Badgerfish. All of the mapping conventions I know of fail to correctly represent “document type” XML such as:
            >
            > <asdf>
            > <a>…</a>
            > <a>…</a>
            > <b>…</b>
            > <a>…</a>
            > </asdf>
            >
            > This speaks to the heart of the difference between XML and JSON. In order to represent something like this in JSON, the contents of the “asdf” element would have to be in an array. This is not an impossible solution, but using that convention throughout makes for very ugly JSON.

            Perhaps I should have worded it as "try to allow...". And that they do
            it with varying level of success -- as you point out, badgerfish fails
            for that case, and others in variety of other ways. Plus even if all
            nuances of XML Infoset were covered (from namespaces to processing
            instructions etc), resulting JSON does look ugly. So yes, this is part
            of the whole impedance part, JSON <> XML.

            -+ Tatu +-
          • Tatu Saloranta
            ... Does this (JSON - xml events) work with any JSON input? Aside from some cases that should be impossible (JSON content can include character content that
            Message 5 of 28 , Sep 14, 2009
            • 0 Attachment
              On Mon, Sep 14, 2009 at 11:17 AM, Mark Joseph <mark@...> wrote:
              > To do the XML to JSON conversion I use our XSLT (which can also go the other way as well)
              >
              > <xsl:output method=’json’/>
              > https://www.p6r.com/articles/2008/11/02/xsloutput-methodjson/

              Does this (JSON -> xml events) work with any JSON input? Aside from
              some cases that should be impossible (JSON content can include
              character content that is illegal in XML), there are smaller questions
              of what to map Arrays to... but those would be solvable. But do
              require adoption some kind of convention. :-)

              So, what do array markers translate to? I'm mostly asking because I
              have been planning addition of some xml compatibility features for
              JSON processor I am working on, and this is one of things where there
              any many options. But if there are emerging (de facto) standards, it'd
              be good to follow.

              -+ Tatu +-
            • Mark Joseph
              So the way the system works is that our JSON parser is called from a plugin to our DOM parser. That plugin calls the DOM parser API that creates nodes in the
              Message 6 of 28 , Sep 14, 2009
              • 0 Attachment
                So the way the system works is that our JSON parser is called from a plugin to our DOM parser. That plugin calls the DOM parser API that creates nodes in the DOM tree.
                This is documented in another article:
                https://www.p6r.com/articles/2008/05/06/xslt-and-xpath-for-json/

                The plugin architecture is also used for XML, where a separate plugin calls our SAX-2 XML parser so they both work the same way.

                This way we convert whatever into a DOM tree and then can run full XSLT 2.0 ( not 1.0 ) and full
                XPATH 2.0 on any of the data.

                -Mark
                P6R Inc


                _____

                From: Tatu Saloranta [mailto:tsaloranta@...]
                To: json@yahoogroups.com
                Sent: Mon, 14 Sep 2009 12:37:39 -0700
                Subject: Re: SV: [json] JSON representation for XML snippet

                On Mon, Sep 14, 2009 at 11:17 AM, Mark Joseph <mark@...> wrote:
                > To do the XML to JSON conversion I use our XSLT (which can also go the other way as well)
                >
                > <xsl:output method=’json’/>
                > https://www.p6r.com/articles/2008/11/02/xsloutput-methodjson/

                Does this (JSON -> xml events) work with any JSON input? Aside from
                some cases that should be impossible (JSON content can include
                character content that is illegal in XML), there are smaller questions
                of what to map Arrays to... but those would be solvable. But do
                require adoption some kind of convention. :-)

                So, what do array markers translate to? I'm mostly asking because I
                have been planning addition of some xml compatibility features for
                JSON processor I am working on, and this is one of things where there
                any many options. But if there are emerging (de facto) standards, it'd
                be good to follow.

                -+ Tatu +-


                ------------------------------------

                Yahoo! Groups Links





                [Non-text portions of this message have been removed]
              • Tatu Saloranta
                ... Right, I did skim through it, it s just that article is omitting a few details. The basic idea of exposing JSON as SAX events is of course simple (and
                Message 7 of 28 , Sep 14, 2009
                • 0 Attachment
                  On Mon, Sep 14, 2009 at 12:46 PM, Mark Joseph <mark@...> wrote:
                  > So the way the system works is that our JSON parser is called from a plugin to our DOM parser.   That plugin calls the DOM parser API that creates nodes in the DOM tree.
                  > This is documented in another article:
                  > https://www.p6r.com/articles/2008/05/06/xslt-and-xpath-for-json/
                  >
                  > The plugin architecture is also used for XML, where a separate plugin calls our SAX-2 XML parser so they both work the same way.

                  Right, I did skim through it, it's just that article is omitting a few
                  details. The basic idea of exposing JSON as SAX events is of course
                  simple (and obvious, but useful): JSON start/end object/array gets
                  converted to SAX start/end element events, no attributes.

                  But one thing I didn't see mentioned was the the question of mapping
                  JSON arrays (it does mention use of "JSON-document” as dummy name for
                  outermost JSON object, which is needed). In XML there are couple of
                  ways of expressing logical arrays (sequences of items), so one has to
                  choose one from alternatives (separate container for array itself? or
                  for elements? or both? and what name to use for either?)
                  So it seems that either JSON arrays are not supported, or that details
                  are just not mentioned.
                  Also: this problem affects JSON output as well.

                  Another smaller issue is handling of JSON content with characters that
                  are legal in JSON, but illegal in XML (like control characters) is not
                  mentioned. Maybe such content is just passed as is; which works ok
                  unless app code is assuming that no such content will be received.

                  -+ Tatu +-
                • Andrea Giammarchi
                  I do not get all these problems ... first of all I expect that JSON to XML will parse JSON first and then create XML via proper namespace/libarry and character
                  Message 8 of 28 , Sep 14, 2009
                  • 0 Attachment
                    I do not get all these problems ... first of all I expect that JSON to XML
                    will parse JSON first and then create XML via proper namespace/libarry and
                    character problem should not exist in this case.

                    Secondly ASAIK JSON escapes a lot of characters adding \uXXXX from 0000 to
                    FFFF, other characters are escaped like \\n and the rest is basically ASCII.
                    Which parser gives you all these problems during convertion, assuming you
                    are avoiding the "to Current Language before, to XML after" strategy?

                    On Mon, Sep 14, 2009 at 9:04 PM, Tatu Saloranta <tsaloranta@...>wrote:

                    > On Mon, Sep 14, 2009 at 12:46 PM, Mark Joseph <mark@...> wrote:
                    > > So the way the system works is that our JSON parser is called from a
                    > plugin to our DOM parser. That plugin calls the DOM parser API that
                    > creates nodes in the DOM tree.
                    > > This is documented in another article:
                    > > https://www.p6r.com/articles/2008/05/06/xslt-and-xpath-for-json/
                    > >
                    > > The plugin architecture is also used for XML, where a separate plugin
                    > calls our SAX-2 XML parser so they both work the same way.
                    >
                    > Right, I did skim through it, it's just that article is omitting a few
                    > details. The basic idea of exposing JSON as SAX events is of course
                    > simple (and obvious, but useful): JSON start/end object/array gets
                    > converted to SAX start/end element events, no attributes.
                    >
                    > But one thing I didn't see mentioned was the the question of mapping
                    > JSON arrays (it does mention use of "JSON-document� as dummy name for
                    > outermost JSON object, which is needed). In XML there are couple of
                    > ways of expressing logical arrays (sequences of items), so one has to
                    > choose one from alternatives (separate container for array itself? or
                    > for elements? or both? and what name to use for either?)
                    > So it seems that either JSON arrays are not supported, or that details
                    > are just not mentioned.
                    > Also: this problem affects JSON output as well.
                    >
                    > Another smaller issue is handling of JSON content with characters that
                    > are legal in JSON, but illegal in XML (like control characters) is not
                    > mentioned. Maybe such content is just passed as is; which works ok
                    > unless app code is assuming that no such content will be received.
                    >
                    > -+ Tatu +-
                    >
                    >
                    > ------------------------------------
                    >
                    > Yahoo! Groups Links
                    >
                    >
                    >
                    >


                    [Non-text portions of this message have been removed]
                  • Mark Joseph
                    But one thing I didn t see mentioned was the the question of mapping JSON arrays (it does mention use of JSON-document” as dummy name for outermost JSON
                    Message 9 of 28 , Sep 14, 2009
                    • 0 Attachment
                      But one thing I didn't see mentioned was the the question of mapping
                      JSON arrays (it does mention use of "JSON-document” as dummy name for
                      outermost JSON object, which is needed). In XML there are couple of
                      ways of expressing logical arrays (sequences of items), so one has to
                      choose one from alternatives (separate container for array itself? or
                      for elements? or both? and what name to use for either?)
                      So it seems that either JSON arrays are not supported, or that details
                      are just not mentioned.
                      Also: this problem affects JSON output as well.
                      The the code that generates JSON output detects an array in the DOM tree and
                      generates a JSON array from it. The "array" are just several nodes in the tree
                      with the same element name that are adjacent to each other.

                      The JSON parsing to DOM nodes just places all the array elements adjacent to each
                      other in the tree with the same name. But this is an internal implementation thing that I could
                      do several ways. (I could add a special node in the DOM tree indicating an array
                      start and array end. Where these nodes are not output.)

                      What is in the DOM tree is not XML and not JSON and not any other format. It
                      is instead an intermediate format with extra "schematic" marker nodes a necessary
                      to indicate other information.


                      Another smaller issue is handling of JSON content with characters that
                      are legal in JSON, but illegal in XML (like control characters) is not
                      mentioned. Maybe such content is just passed as is; which works ok
                      unless app code is assuming that no such content will be received.
                      Well I can't discuss everything in a single article, but in the DOM tree there are
                      no illegal characaters since at that point its not XML. However, when you take
                      the DOM tree and want to output it as XML then there are standard escape/encoding
                      rules in XML that are used to force proper XML.

                      What is really nice about our approach is now I can add another plugin that takes our
                      ASN.1 parser (for example) and converts that into a DOM tree (since it has structure too). And then
                      do whatever I want to it.



                      Best,
                      Mark
                      P6R, Inc




                      -+ Tatu +-


                      ------------------------------------

                      Yahoo! Groups Links





                      [Non-text portions of this message have been removed]
                    • Mark Joseph
                      ... *************************************** My Response: The the code that generates JSON output detects an array in the DOM tree and generates a JSON array
                      Message 10 of 28 , Sep 14, 2009
                      • 0 Attachment
                        Sorry the previous version of this message was hard to read:


                        >But one thing I didn't see mentioned was the the question of mapping
                        >JSON arrays (it does mention use of "JSON-document” as dummy name for
                        >outermost JSON object, which is needed). In XML there are couple of
                        >ways of expressing logical arrays (sequences of items), so one has to
                        >choose one from alternatives (separate container for array itself? or
                        >for elements? or both? and what name to use for either?)
                        >So it seems that either JSON arrays are not supported, or that details
                        >are just not mentioned.
                        >Also: this problem affects JSON output as well.


                        ***************************************
                        My Response:

                        The the code that generates JSON output detects an array in the DOM tree and
                        generates a JSON array from it. The "array" are just several nodes in the tree
                        with the same element name that are adjacent to each other.

                        The JSON parsing to DOM nodes just places all the array elements adjacent to each
                        other in the tree with the same name. But this is an internal implementation thing that I could
                        do several ways. (I could add a special node in the DOM tree indicating an array
                        start and array end. Where these nodes are not output.)

                        What is in the DOM tree is not XML and not JSON and not any other format. It
                        is instead an intermediate format with extra "schematic" marker nodes a necessary
                        to indicate other information.

                        ***************************************


                        >Another smaller issue is handling of JSON content with characters that
                        >are legal in JSON, but illegal in XML (like control characters) is not
                        >mentioned. Maybe such content is just passed as is; which works ok
                        >unless app code is assuming that no such content will be received.


                        *****************************************
                        My Response:

                        Well I can't discuss everything in a single article, but in the DOM tree there are
                        no illegal characaters since at that point its not XML. However, when you take
                        the DOM tree and want to output it as XML then there are standard escape/encoding
                        rules in XML that are used to force proper XML.

                        What is really nice about our approach is now I can add another plugin that takes our
                        ASN.1 parser (for example) and converts that into a DOM tree (since it has structure too). And then
                        do whatever I want to it.

                        Best,
                        Mark
                        P6R, Inc

                        ****************************************
                      • Shalab Goel
                        Thank you for all the responses. I guess there were two parts to it. I was specifically interested in your insights on a XML element with both text and
                        Message 11 of 28 , Sep 14, 2009
                        • 0 Attachment
                          Thank you for all the responses. I guess there were two parts to it. I was
                          specifically interested in your insights on a XML element with both text and
                          attributes
                          can be represented in JSON.

                          <attribute a2="v2">value2</attribute>

                          If XML were

                          <attribute a2="v2">value2</attribute>

                          equivalent JSON could be

                          {"attribute" : "value2"}

                          if XML were

                          <attribute a2="v2" />

                          JSON could be

                          {
                          "attribute" :
                          { "a2" : "v2" }
                          }

                          But how about when both XML element's text and attributes are specified
                          as in

                          <attribute a2="v2">value2</attribute>

                          Thanks
                          Shalab

                          On Mon, Sep 14, 2009 at 1:36 PM, Mark Joseph <mark@...> wrote:

                          >
                          >
                          > But one thing I didn't see mentioned was the the question of mapping
                          > JSON arrays (it does mention use of "JSON-document� as dummy name for
                          > outermost JSON object, which is needed). In XML there are couple of
                          > ways of expressing logical arrays (sequences of items), so one has to
                          > choose one from alternatives (separate container for array itself? or
                          > for elements? or both? and what name to use for either?)
                          > So it seems that either JSON arrays are not supported, or that details
                          > are just not mentioned.
                          > Also: this problem affects JSON output as well.
                          > The the code that generates JSON output detects an array in the DOM tree
                          > and
                          > generates a JSON array from it. The "array" are just several nodes in the
                          > tree
                          > with the same element name that are adjacent to each other.
                          >
                          > The JSON parsing to DOM nodes just places all the array elements adjacent
                          > to each
                          > other in the tree with the same name. But this is an internal
                          > implementation thing that I could
                          > do several ways. (I could add a special node in the DOM tree indicating an
                          > array
                          > start and array end. Where these nodes are not output.)
                          >
                          > What is in the DOM tree is not XML and not JSON and not any other format.
                          > It
                          > is instead an intermediate format with extra "schematic" marker nodes a
                          > necessary
                          > to indicate other information.
                          >
                          > Another smaller issue is handling of JSON content with characters that
                          > are legal in JSON, but illegal in XML (like control characters) is not
                          > mentioned. Maybe such content is just passed as is; which works ok
                          > unless app code is assuming that no such content will be received.
                          > Well I can't discuss everything in a single article, but in the DOM tree
                          > there are
                          > no illegal characaters since at that point its not XML. However, when you
                          > take
                          > the DOM tree and want to output it as XML then there are standard
                          > escape/encoding
                          > rules in XML that are used to force proper XML.
                          >
                          > What is really nice about our approach is now I can add another plugin that
                          > takes our
                          > ASN.1 parser (for example) and converts that into a DOM tree (since it has
                          > structure too). And then
                          > do whatever I want to it.
                          >
                          > Best,
                          > Mark
                          > P6R, Inc
                          >
                          > -+ Tatu +-
                          >
                          >
                          > ------------------------------------
                          >
                          > Yahoo! Groups Links
                          >
                          >
                          >
                          >
                          >
                          > [Non-text portions of this message have been removed]
                          >
                          >
                          >


                          [Non-text portions of this message have been removed]
                        • Andrea Giammarchi
                          just use a non valid attribute name as JSON property, so you won t have ambiguity in the parser. value2 will be
                          Message 12 of 28 , Sep 14, 2009
                          • 0 Attachment
                            just use a non valid attribute name as JSON property, so you won't have
                            ambiguity in the parser.

                            <attribute a2="v2">value2</attribute>
                            will be
                            {"attribute":{"a2":"v2"},"#text":"value2"}

                            as example ... while JSONML uses this kind of schema

                            ["nodeName",{"a2":"v2"},"text or nested nodes"]

                            so that this:

                            <attributes>
                            <attribute a2="v2">value2</attribute>
                            </attributes>

                            will be this

                            ["attributes",{},["attribute",{"a2":"v2"},"value2"]]

                            Regards

                            On Mon, Sep 14, 2009 at 10:23 PM, Shalab Goel <goel.shalab@...> wrote:

                            >
                            > But how about when both XML element's text and attributes are specified
                            > as in
                            >
                            > <attribute a2="v2">value2</attribute>
                            >
                            > Thanks
                            > Shalab
                            >


                            [Non-text portions of this message have been removed]
                          • Mark Joseph
                            ********************************** From: Shalab Goel [mailto:goel.shalab@gmail.com] To: json@yahoogroups.com Sent: Mon, 14 Sep 2009 14:23:34 -0700 Subject: Re:
                            Message 13 of 28 , Sep 14, 2009
                            • 0 Attachment
                              **********************************
                              From: Shalab Goel [mailto:goel.shalab@...]
                              To: json@yahoogroups.com
                              Sent: Mon, 14 Sep 2009 14:23:34 -0700
                              Subject: Re: SV: [json] JSON representation for XML snippet

                              Thank you for all the responses. I guess there were two parts to it. I was
                              specifically interested in your insights on a XML element with both text and
                              attributes
                              can be represented in JSON.

                              <attribute a2="v2">value2</attribute>

                              If XML were

                              <attribute a2="v2">value2</attribute>

                              equivalent JSON could be

                              {"attribute" : "value2"}

                              if XML were

                              <attribute a2="v2" />

                              JSON could be

                              {
                              "attribute" :
                              { "a2" : "v2" }
                              }

                              But how about when both XML element's text and attributes are specified
                              as in

                              <attribute a2="v2">value2</attribute>
                              *************************************


                              It would be great if there was a standard defined for the transformation, but
                              other than that I can only mention what I have done.

                              I have played with both formats:

                              a flat format:
                              { "attribute" : "value2",
                              "a2" : "v2"
                              }

                              OR

                              An array format:
                              { "attribute" : [ { "a2" : "v2" }, { "value2" } ] }


                              Of course, with either of these outputs we lose something and cannot easily turn this
                              back into XML afterwards. Since JSON has no attributes I have no solution unless
                              everyone agrees to what the mapping should be.


                              Best,

                              Mark Joseph, Ph.D.
                              President
                              P6R, Inc
                              408-205-0361
                              mark@...
                              Skype: markjoseph_sc
                            • Tatu Saloranta
                              ... Ok. So DOM tree does have extra metadata that indicates this array-ness . I assumed that DOM tree itself had no knowledge of this, given that SAX API
                              Message 14 of 28 , Sep 14, 2009
                              • 0 Attachment
                                On Mon, Sep 14, 2009 at 1:53 PM, Mark Joseph <mark@...> wrote:
                                > Sorry the previous version of this message was hard to read:

                                >>But one thing I didn't see mentioned was the the question of mapping
                                >>JSON arrays (it does mention use of "JSON-document” as dummy name for
                                ...
                                > ***************************************
                                > My Response:
                                >
                                > The the code that generates JSON output detects an array in the DOM tree and
                                > generates a JSON array from it.   The "array" are just several nodes in the tree
                                > with the same element name that are adjacent to each other.

                                Ok. So DOM tree does have extra metadata that indicates this "array-ness".

                                I assumed that DOM tree itself had no knowledge of this, given that
                                SAX API would not have a way of indicating such data.
                                But if API is just SAX-like (or extension of SAX with additional
                                callback types, startArray/endArray), this could be handled.

                                > The JSON parsing to DOM nodes just places all the array elements adjacent to each
                                > other in the tree with the same name.   But this is an internal implementation thing that I could
                                > do several ways.   (I could add a special node in the DOM tree indicating an array
                                > start and array end.  Where these nodes are not output.)

                                Right. There are multiple ways of exposing it, that is why I asked.

                                > What is in the DOM tree is not XML and not JSON and not any other format.  It
                                > is instead an intermediate format with extra "schematic" marker nodes a necessary
                                > to indicate other information.

                                Ok.

                                > ***************************************
                                >
                                >>Another smaller issue is handling of JSON content with characters that
                                >>are legal in JSON, but illegal in XML (like control characters) is not
                                >>mentioned. Maybe such content is just passed as is; which works ok
                                >>unless app code is assuming that no such content will be received.
                                >
                                > *****************************************
                                > My Response:
                                >
                                > Well I can't discuss everything in a single article, but in the DOM tree there are
                                > no illegal characaters since at that point its not XML.   However, when you take
                                > the DOM tree and want to output it as XML then there are standard escape/encoding
                                > rules in XML that are used to force proper XML.

                                Yes, except that this is not possible in xml 1.0, not even with
                                character entities. There is no way include control characters (except
                                for standard tab, lf, cr) in xml. This is different from having to
                                escape less-than and ampersand characters.
                                XML 1.1 allows for use of character entities for many of these
                                characters, not including null.

                                But I guess this is usually not a significant problem in practice.

                                > What is really nice about our approach is now I can add another plugin that takes our
                                > ASN.1 parser (for example) and converts that into a DOM tree (since it has structure too).   And then
                                > do whatever I want to it.

                                It is good to have interoperability tools, and I think this use case
                                makes sense. It is easier to map JSON to XML if necessary than the
                                other way around.

                                Thank you for your explanation,

                                -+ Tatu +-
                              • Mark Joseph
                                ******************************************************* Ok. So DOM tree does have extra metadata that indicates this array-ness . I assumed that DOM tree
                                Message 15 of 28 , Sep 14, 2009
                                • 0 Attachment
                                  *******************************************************
                                  Ok. So DOM tree does have extra metadata that indicates this "array-ness".

                                  I assumed that DOM tree itself had no knowledge of this, given that
                                  SAX API would not have a way of indicating such data.
                                  But if API is just SAX-like (or extension of SAX with additional
                                  callback types, startArray/endArray), this could be handled.
                                  ******************************************************

                                  Our JSON parser does this:
                                  https://www.p6r.com/articles/2008/05/22/a-sax-like-parser-for-json/

                                  Its sax2 like in that its event based.


                                  >XML 1.1 allows for use of character entities for many of these
                                  >characters, not including null.
                                  >
                                  Since there is no standard way to handle this my code actually output
                                  the text "null" so you can see at least what the value was meant to be.



                                  Best,
                                  Mark
                                  P6R, Inc
                                • Tatu Saloranta
                                  On Mon, Sep 14, 2009 at 1:33 PM, Andrea Giammarchi ... Unfortunately, no. I am specifically referring to XML inability to contain control characters like 0xA.
                                  Message 16 of 28 , Sep 14, 2009
                                  • 0 Attachment
                                    On Mon, Sep 14, 2009 at 1:33 PM, Andrea Giammarchi
                                    <andrea.giammarchi@...> wrote:
                                    > I do not get all these problems ... first of all I expect that JSON to XML
                                    > will parse JSON first and then create XML via proper namespace/libarry and
                                    > character problem should not exist in this case.

                                    Unfortunately, no. I am specifically referring to XML inability to
                                    contain control characters like 0xA.
                                    There is no way to include those in XML 1.0 documents, not even by
                                    using character entities (char entity production must match
                                    valid-char, which excludes these). They can be included in JSON via
                                    escape mechanism.
                                    Reverse is not a problem as JSON can contain any Unicode character;
                                    any without escaping. I consider this a good thing (at least for
                                    String values).

                                    -+ Tatu +-
                                  • Mark Joseph
                                    Handling XML attributes when converting to JSON: ************************************** value2 will be
                                    Message 17 of 28 , Sep 16, 2009
                                    • 0 Attachment
                                      Handling XML attributes when converting to JSON:
                                      **************************************
                                      <attribute a2="v2">value2</attribute>
                                      will be
                                      {"attribute":{"a2":"v2"},"#text":"value2"}

                                      as example ... while JSONML uses this kind of schema

                                      ["nodeName",{"a2":"v2"},"text or nested nodes"]

                                      so that this:

                                      <attributes>
                                      <attribute a2="v2">value2</attribute>
                                      </attributes>

                                      will be this

                                      ["attributes",{},["attribute",{"a2":"v2"},"value2"]]
                                      ****************************************

                                      So all of the above works well when you have simple XML.
                                      But with something like:

                                      <node1 a="45">
                                      <node2 b="9" c="hithere">
                                      <node3 d="abc">
                                      <node4 e="12345">JSON has no attributes</node4>
                                      </node3>
                                      </node2>
                                      Now is the time for all good men to come to the aid of their party

                                      <node5 d="45">temperature is 70 degrees today</node5>
                                      </node1>

                                      The resulting JSON is going to be "ugly". Many added arrays
                                      are added to handle the attributes and nested nodes now appear in the
                                      added arrays. To me this adds a lot of extra complexity that I am
                                      not sure I want.



                                      Best,
                                      Mark Joseph, Ph.D.
                                      P6R, Inc
                                    • stephen.mckamey
                                      The encoding used by JsonML isn t prioritized to be pretty or even really encoded by humans. It is intended to be compact and loss-less.
                                      Message 18 of 28 , Sep 17, 2009
                                      • 0 Attachment
                                        The encoding used by JsonML <http://jsonml.org> isn't prioritized to be "pretty" or even really encoded by humans. It is intended to be compact and loss-less. This means it can unambiguously encode and decode valid XML. Namespaces are handled the same way as XML 1.0: as part of the element (or attribute) name.

                                        Off-topic: Where JsonML really fills a void is its ability to be extended to be a full intermediate language for client-side templates. Templates are written by humans in an ASP/JSP style syntax and then compiled to JsonML+Browser-Side Templates (JBST) <http://bit.ly/2poc6d>. No parsing has to take place in the browser, and the site markup may be fully compacted and cached with the rest of the scripts as it is now pure JavaScript.

                                        --- In json@yahoogroups.com, "Mark Joseph" <mark@...> wrote:
                                        >
                                        >
                                        > Handling XML attributes when converting to JSON:
                                        > **************************************
                                        > <attribute a2="v2">value2</attribute>
                                        > will be
                                        > {"attribute":{"a2":"v2"},"#text":"value2"}
                                        >
                                        > as example ... while JSONML uses this kind of schema
                                        >
                                        > ["nodeName",{"a2":"v2"},"text or nested nodes"]
                                        >
                                        > so that this:
                                        >
                                        > <attributes>
                                        > <attribute a2="v2">value2</attribute>
                                        > </attributes>
                                        >
                                        > will be this
                                        >
                                        > ["attributes",{},["attribute",{"a2":"v2"},"value2"]]
                                        > ****************************************
                                        >
                                        > So all of the above works well when you have simple XML.
                                        > But with something like:
                                        >
                                        > <node1 a="45">
                                        > <node2 b="9" c="hithere">
                                        > <node3 d="abc">
                                        > <node4 e="12345">JSON has no attributes</node4>
                                        > </node3>
                                        > </node2>
                                        > Now is the time for all good men to come to the aid of their party
                                        >
                                        > <node5 d="45">temperature is 70 degrees today</node5>
                                        > </node1>
                                        >
                                        > The resulting JSON is going to be "ugly". Many added arrays
                                        > are added to handle the attributes and nested nodes now appear in the
                                        > added arrays. To me this adds a lot of extra complexity that I am
                                        > not sure I want.
                                        >
                                        >
                                        >
                                        > Best,
                                        > Mark Joseph, Ph.D.
                                        > P6R, Inc
                                      • Mark Joseph
                                        For people interested in this topic. We are always open to comments and questions. https://www.p6r.com/articles/2010/04/05/xml-to-json-and-back/ Best, Mark
                                        Message 19 of 28 , Apr 5 5:47 PM
                                        • 0 Attachment
                                          For people interested in this topic. We are always open to comments and questions.

                                          https://www.p6r.com/articles/2010/04/05/xml-to-json-and-back/


                                          Best,

                                          Mark Joseph, Ph.D.
                                          President
                                          P6R, Inc
                                          408-205-0361
                                          mark@...
                                          Skype: markjoseph_sc



                                          [Non-text portions of this message have been removed]
                                        • Dennis Gearon
                                          I m not really interested in this at the moment. BUT, very nice technical work! If I do need it in the future, it s nice to see good quality ideas and
                                          Message 20 of 28 , Apr 5 9:02 PM
                                          • 0 Attachment
                                            I'm not really interested in this at the moment.

                                            BUT, very nice technical work! If I do need it in the future, it's nice to see good quality ideas and implentation that I can look for and utilize.

                                            Keep up the good work.

                                            Dennis Gearon



                                            Signature Warning

                                            ----------------

                                            EARTH has a Right To Life,

                                            otherwise we all die.



                                            Read 'Hot, Flat, and Crowded'

                                            Laugh at http://www.yert.com/film.php

                                            --- On Mon, 4/5/10, Mark Joseph <mark@...> wrote:

                                            From: Mark Joseph <mark@...>
                                            Subject: [json] Where our JSON product is heading: XML to JSON and Back
                                            To: json@yahoogroups.com
                                            Date: Monday, April 5, 2010, 5:47 PM







                                             









                                            For people interested in this topic. We are always open to comments and questions.



                                            https://www. p6r.com/articles /2010/04/ 05/xml-to- json-and- back/



                                            Best,



                                            Mark Joseph, Ph.D.

                                            President

                                            P6R, Inc

                                            408-205-0361

                                            mark@...

                                            Skype: markjoseph_sc



                                            [Non-text portions of this message have been removed]






















                                            [Non-text portions of this message have been removed]
                                          • stephen.mckamey
                                            JsonML ( http://jsonml.org ) handles all of these issues and has been embraced by quite a number of places. Many JSON encoders already include support. It
                                            Message 21 of 28 , Apr 6 10:11 AM
                                            • 0 Attachment
                                              JsonML ( http://jsonml.org ) handles all of these issues and has been embraced by quite a number of places. Many JSON encoders already include support.

                                              It handles namespaces the same way that XML 1.0 did: include the name as "prefix:local-name" and the URI to prefix mapping (xmlns:abc="http://example.com/abc") as the attribute of the node that declared it.

                                              An early implementation of JsonML took a similar approach to including a child object, but ultimately after some design discussions with Douglas Crockford, his suggestion was to make the actual element an array like the child object and have the element name be the first item.

                                              This positional structure has been the biggest part that people have disliked about JsonML, but yet in many XML documents (XHTML for example, being the primary use case) position of the child nodes is critical to the meaning of the document. So you get much smaller documents when you just add the element name as the first child and make elements arrays.

                                              I'd encourage you to embrace JsonML and contribute to a standard that has been around for four years already rather than creating a slightly different approach.


                                              --- In json@yahoogroups.com, "Mark Joseph" <mark@...> wrote:
                                              >
                                              > For people interested in this topic. We are always open to comments and questions.
                                              >
                                              > https://www.p6r.com/articles/2010/04/05/xml-to-json-and-back/
                                              >
                                              >
                                              > Best,
                                              >
                                              > Mark Joseph, Ph.D.
                                              > President
                                              > P6R, Inc
                                              > 408-205-0361
                                              > mark@...
                                              > Skype: markjoseph_sc
                                              >
                                              >
                                              >
                                              > [Non-text portions of this message have been removed]
                                              >
                                            • stephen.mckamey
                                              Not that ugly: [ node1 , { a : 45 }, [ node2 , { b : 9 , c : hithere }, [ node3 , { d : abc }, [ node4 , { e : 12345 }, JSON has no attributes ] ] ], Now is
                                              Message 22 of 28 , Apr 6 10:20 AM
                                              • 0 Attachment
                                                Not that ugly:

                                                ["node1", {"a":"45"},
                                                ["node2", {"b":"9", "c":"hithere"},
                                                ["node3", {"d":"abc"},
                                                ["node4", {"e":"12345"}, "JSON has no attributes"]
                                                ]
                                                ],
                                                "Now is the time for all good men to come to the aid of their party",

                                                ["node5", {"d":"45"}, "temperature is 70 degrees today"]
                                                ]

                                                --- In json@yahoogroups.com, "Mark Joseph" <mark@...> wrote:
                                                >
                                                >
                                                > Handling XML attributes when converting to JSON:
                                                > **************************************
                                                > <attribute a2="v2">value2</attribute>
                                                > will be
                                                > {"attribute":{"a2":"v2"},"#text":"value2"}
                                                >
                                                > as example ... while JSONML uses this kind of schema
                                                >
                                                > ["nodeName",{"a2":"v2"},"text or nested nodes"]
                                                >
                                                > so that this:
                                                >
                                                > <attributes>
                                                > <attribute a2="v2">value2</attribute>
                                                > </attributes>
                                                >
                                                > will be this
                                                >
                                                > ["attributes",{},["attribute",{"a2":"v2"},"value2"]]
                                                > ****************************************
                                                >
                                                > So all of the above works well when you have simple XML.
                                                > But with something like:
                                                >
                                                > <node1 a="45">
                                                > <node2 b="9" c="hithere">
                                                > <node3 d="abc">
                                                > <node4 e="12345">JSON has no attributes</node4>
                                                > </node3>
                                                > </node2>
                                                > Now is the time for all good men to come to the aid of their party
                                                >
                                                > <node5 d="45">temperature is 70 degrees today</node5>
                                                > </node1>
                                                >
                                                > The resulting JSON is going to be "ugly". Many added arrays
                                                > are added to handle the attributes and nested nodes now appear in the
                                                > added arrays. To me this adds a lot of extra complexity that I am
                                                > not sure I want.
                                                >
                                                >
                                                >
                                                > Best,
                                                > Mark Joseph, Ph.D.
                                                > P6R, Inc
                                                >
                                              • Mark Joseph
                                                Cool stuff, can you show me an example of how JsonML handles XML mixed content, that is not clear to me from the web site. And just so it is clear to me, the
                                                Message 23 of 28 , Apr 6 11:19 AM
                                                • 0 Attachment
                                                  Cool stuff, can you show me an example of how JsonML handles XML mixed content, that is not clear to me from the web site.


                                                  And just so it is clear to me, the namespace example would be something like:

                                                  <description abc="http://example.com"><abc:title>hi there</abc:title></description>

                                                  becomes

                                                  [ "description", {"abc" : "http://example.com"},
                                                  [ "abc:title", {}, "hi there" ]
                                                  ]

                                                  So the JSON application has to find the meaning of "abc:title", if it cares, like XML applications do by looking for the first enclosing element with
                                                  a definition for "abc"?



                                                  Thanks,

                                                  Mark Joseph, Ph.D.
                                                  President
                                                  P6R, Inc
                                                  408-205-0361
                                                  mark@...
                                                  Skype: markjoseph_sc
                                                  _____

                                                  From: stephen.mckamey [mailto:stephen@...]
                                                  To: json@yahoogroups.com
                                                  Sent: Tue, 06 Apr 2010 10:11:22 -0700
                                                  Subject: [json] Re: Where our JSON product is heading: XML to JSON and Back








                                                  JsonML ( http://jsonml.org ) handles all of these issues and has been embraced by quite a number of places. Many JSON encoders already include support.

                                                  It handles namespaces the same way that XML 1.0 did: include the name as "prefix:local-name" and the URI to prefix mapping (xmlns:abc="http://example.com/abc") as the attribute of the node that declared it.

                                                  An early implementation of JsonML took a similar approach to including a child object, but ultimately after some design discussions with Douglas Crockford, his suggestion was to make the actual element an array like the child object and have the element name be the first item.

                                                  This positional structure has been the biggest part that people have disliked about JsonML, but yet in many XML documents (XHTML for example, being the primary use case) position of the child nodes is critical to the meaning of the document. So you get much smaller documents when you just add the element name as the first child and make elements arrays.

                                                  I'd encourage you to embrace JsonML and contribute to a standard that has been around for four years already rather than creating a slightly different approach.

                                                  --- In json@yahoogroups.com, "Mark Joseph" <mark@...> wrote:
                                                  >
                                                  > For people interested in this topic. We are always open to comments and questions.
                                                  >
                                                  > https://www.p6r.com/articles/2010/04/05/xml-to-json-and-back/
                                                  >
                                                  >
                                                  > Best,
                                                  >
                                                  > Mark Joseph, Ph.D.
                                                  > President
                                                  > P6R, Inc
                                                  > 408-205-0361
                                                  > mark@...
                                                  > Skype: markjoseph_sc
                                                  >
                                                  >
                                                  >
                                                  > [Non-text portions of this message have been removed]
                                                  >




                                                  [Non-text portions of this message have been removed]
                                                • Mark Joseph
                                                  Ok I think I see how mixed content works in JsonML: hi there joe how are you becomes [ description ,
                                                  Message 24 of 28 , Apr 6 11:35 AM
                                                  • 0 Attachment
                                                    Ok I think I see how mixed content works in JsonML:

                                                    <description lang="en-us"> hi there <bold>joe</bold> how are you </descrption>

                                                    becomes

                                                    [ "description", {"lang":"en-us"},
                                                    " hi there ",
                                                    [ "bold", "joe" ],
                                                    " how are you "
                                                    ]

                                                    Is that right?


                                                    Best,

                                                    Mark Joseph, Ph.D.
                                                    President
                                                    P6R, Inc
                                                    408-205-0361
                                                    mark@...
                                                    Skype: markjoseph_sc
                                                    _____

                                                    From: stephen.mckamey [mailto:stephen@...]
                                                    To: json@yahoogroups.com
                                                    Sent: Tue, 06 Apr 2010 10:20:12 -0700
                                                    Subject: Re: SV: [json] JSON representation for XML snippet






                                                    Not that ugly:

                                                    ["node1", {"a":"45"},
                                                    ["node2", {"b":"9", "c":"hithere"},
                                                    ["node3", {"d":"abc"},
                                                    ["node4", {"e":"12345"}, "JSON has no attributes"]
                                                    ]
                                                    ],
                                                    "Now is the time for all good men to come to the aid of their party",

                                                    ["node5", {"d":"45"}, "temperature is 70 degrees today"]
                                                    ]

                                                    --- In json@yahoogroups.com, "Mark Joseph" <mark@...> wrote:
                                                    >
                                                    >
                                                    > Handling XML attributes when converting to JSON:
                                                    > **************************************
                                                    > <attribute a2="v2">value2</attribute>
                                                    > will be
                                                    > {"attribute":{"a2":"v2"},"#text":"value2"}
                                                    >
                                                    > as example ... while JSONML uses this kind of schema
                                                    >
                                                    > ["nodeName",{"a2":"v2"},"text or nested nodes"]
                                                    >
                                                    > so that this:
                                                    >
                                                    > <attributes>
                                                    > <attribute a2="v2">value2</attribute>
                                                    > </attributes>
                                                    >
                                                    > will be this
                                                    >
                                                    > ["attributes",{},["attribute",{"a2":"v2"},"value2"]]
                                                    > ****************************************
                                                    >
                                                    > So all of the above works well when you have simple XML.
                                                    > But with something like:
                                                    >
                                                    > <node1 a="45">
                                                    > <node2 b="9" c="hithere">
                                                    > <node3 d="abc">
                                                    > <node4 e="12345">JSON has no attributes</node4>
                                                    > </node3>
                                                    > </node2>
                                                    > Now is the time for all good men to come to the aid of their party
                                                    >
                                                    > <node5 d="45">temperature is 70 degrees today</node5>
                                                    > </node1>
                                                    >
                                                    > The resulting JSON is going to be "ugly". Many added arrays
                                                    > are added to handle the attributes and nested nodes now appear in the
                                                    > added arrays. To me this adds a lot of extra complexity that I am
                                                    > not sure I want.
                                                    >
                                                    >
                                                    >
                                                    > Best,
                                                    > Mark Joseph, Ph.D.
                                                    > P6R, Inc
                                                    >




                                                    [Non-text portions of this message have been removed]
                                                  • stephen.mckamey
                                                    The attributes object is optional (see the BNF at http://jsonml.org) so you can drop it if empty to make more compact. The example XML:
                                                    Message 25 of 28 , Apr 6 11:43 AM
                                                    • 0 Attachment
                                                      The attributes object is optional (see the BNF at http://jsonml.org) so you can drop it if empty to make more compact.

                                                      The example XML:

                                                      <description abc="http://example.com">
                                                      <abc:title>hi there</abc:title>
                                                      </description>

                                                      would encode in JsonML as:

                                                      ["description", {"abc":"http://example.com"},
                                                      ["abc:title", "hi there"]
                                                      ]

                                                      To encode mixed content, I think you mean like this:

                                                      <div class="section">
                                                      <p class="description">This is how <b>inline elements</b> get marked up.</p>
                                                      </div>

                                                      would encode to the JsonML:

                                                      ["div", {"class":"section"},
                                                      ["p", {"class":"description"}, "This is how ", ["b", "inline elements"], " get marked up."]
                                                      ]

                                                      Optionally, you could even encode the document whitespace as well if this was significant to the original XML.

                                                      ["div", {"class":"section"},
                                                      "\r\n\t",
                                                      ["p", {"class":"description"}, "This is how ", ["b", "inline elements"], " get marked up."],
                                                      "\r\n"
                                                      ]

                                                      --- In json@yahoogroups.com, "Mark Joseph" <mark@...> wrote:
                                                      >
                                                      > Cool stuff, can you show me an example of how JsonML handles XML mixed content, that is not clear to me from the web site.
                                                      >
                                                      >
                                                      > And just so it is clear to me, the namespace example would be something like:
                                                      >
                                                      > <description abc="http://example.com"><abc:title>hi there</abc:title></description>
                                                      >
                                                      > becomes
                                                      >
                                                      > [ "description", {"abc" : "http://example.com"},
                                                      > [ "abc:title", {}, "hi there" ]
                                                      > ]
                                                      >
                                                      > So the JSON application has to find the meaning of "abc:title", if it cares, like XML applications do by looking for the first enclosing element with
                                                      > a definition for "abc"?
                                                      >
                                                      >
                                                      >
                                                      > Thanks,
                                                      >
                                                      > Mark Joseph, Ph.D.
                                                      > President
                                                      > P6R, Inc
                                                      > 408-205-0361
                                                      > mark@...
                                                      > Skype: markjoseph_sc
                                                      > _____
                                                      >
                                                      > From: stephen.mckamey [mailto:stephen@...]
                                                      > To: json@yahoogroups.com
                                                      > Sent: Tue, 06 Apr 2010 10:11:22 -0700
                                                      > Subject: [json] Re: Where our JSON product is heading: XML to JSON and Back
                                                      >
                                                      >
                                                      >
                                                      >
                                                      >
                                                      >
                                                      >
                                                      >
                                                      > JsonML ( http://jsonml.org ) handles all of these issues and has been embraced by quite a number of places. Many JSON encoders already include support.
                                                      >
                                                      > It handles namespaces the same way that XML 1.0 did: include the name as "prefix:local-name" and the URI to prefix mapping (xmlns:abc="http://example.com/abc") as the attribute of the node that declared it.
                                                      >
                                                      > An early implementation of JsonML took a similar approach to including a child object, but ultimately after some design discussions with Douglas Crockford, his suggestion was to make the actual element an array like the child object and have the element name be the first item.
                                                      >
                                                      > This positional structure has been the biggest part that people have disliked about JsonML, but yet in many XML documents (XHTML for example, being the primary use case) position of the child nodes is critical to the meaning of the document. So you get much smaller documents when you just add the element name as the first child and make elements arrays.
                                                      >
                                                      > I'd encourage you to embrace JsonML and contribute to a standard that has been around for four years already rather than creating a slightly different approach.
                                                      >
                                                      > --- In json@yahoogroups.com, "Mark Joseph" <mark@> wrote:
                                                      > >
                                                      > > For people interested in this topic. We are always open to comments and questions.
                                                      > >
                                                      > > https://www.p6r.com/articles/2010/04/05/xml-to-json-and-back/
                                                      > >
                                                      > >
                                                      > > Best,
                                                      > >
                                                      > > Mark Joseph, Ph.D.
                                                      > > President
                                                      > > P6R, Inc
                                                      > > 408-205-0361
                                                      > > mark@
                                                      > > Skype: markjoseph_sc
                                                      > >
                                                      > >
                                                      > >
                                                      > > [Non-text portions of this message have been removed]
                                                      > >
                                                      >
                                                      >
                                                      >
                                                      >
                                                      > [Non-text portions of this message have been removed]
                                                      >
                                                    • stephen.mckamey
                                                      Exactly. We were posting very similar examples at the same time. :)
                                                      Message 26 of 28 , Apr 6 11:45 AM
                                                      • 0 Attachment
                                                        Exactly. We were posting very similar examples at the same time. :)

                                                        --- In json@yahoogroups.com, "Mark Joseph" <mark@...> wrote:
                                                        >
                                                        > Ok I think I see how mixed content works in JsonML:
                                                        >
                                                        > <description lang="en-us"> hi there <bold>joe</bold> how are you </descrption>
                                                        >
                                                        > becomes
                                                        >
                                                        > [ "description", {"lang":"en-us"},
                                                        > " hi there ",
                                                        > [ "bold", "joe" ],
                                                        > " how are you "
                                                        > ]
                                                        >
                                                        > Is that right?
                                                        >
                                                        >
                                                        > Best,
                                                        >
                                                        > Mark Joseph, Ph.D.
                                                        > President
                                                        > P6R, Inc
                                                        > 408-205-0361
                                                        > mark@...
                                                        > Skype: markjoseph_sc
                                                        > _____
                                                        >
                                                        > From: stephen.mckamey [mailto:stephen@...]
                                                        > To: json@yahoogroups.com
                                                        > Sent: Tue, 06 Apr 2010 10:20:12 -0700
                                                        > Subject: Re: SV: [json] JSON representation for XML snippet
                                                        >
                                                        >
                                                        >
                                                        >
                                                        >
                                                        >
                                                        > Not that ugly:
                                                        >
                                                        > ["node1", {"a":"45"},
                                                        > ["node2", {"b":"9", "c":"hithere"},
                                                        > ["node3", {"d":"abc"},
                                                        > ["node4", {"e":"12345"}, "JSON has no attributes"]
                                                        > ]
                                                        > ],
                                                        > "Now is the time for all good men to come to the aid of their party",
                                                        >
                                                        > ["node5", {"d":"45"}, "temperature is 70 degrees today"]
                                                        > ]
                                                        >
                                                        > --- In json@yahoogroups.com, "Mark Joseph" <mark@> wrote:
                                                        > >
                                                        > >
                                                        > > Handling XML attributes when converting to JSON:
                                                        > > **************************************
                                                        > > <attribute a2="v2">value2</attribute>
                                                        > > will be
                                                        > > {"attribute":{"a2":"v2"},"#text":"value2"}
                                                        > >
                                                        > > as example ... while JSONML uses this kind of schema
                                                        > >
                                                        > > ["nodeName",{"a2":"v2"},"text or nested nodes"]
                                                        > >
                                                        > > so that this:
                                                        > >
                                                        > > <attributes>
                                                        > > <attribute a2="v2">value2</attribute>
                                                        > > </attributes>
                                                        > >
                                                        > > will be this
                                                        > >
                                                        > > ["attributes",{},["attribute",{"a2":"v2"},"value2"]]
                                                        > > ****************************************
                                                        > >
                                                        > > So all of the above works well when you have simple XML.
                                                        > > But with something like:
                                                        > >
                                                        > > <node1 a="45">
                                                        > > <node2 b="9" c="hithere">
                                                        > > <node3 d="abc">
                                                        > > <node4 e="12345">JSON has no attributes</node4>
                                                        > > </node3>
                                                        > > </node2>
                                                        > > Now is the time for all good men to come to the aid of their party
                                                        > >
                                                        > > <node5 d="45">temperature is 70 degrees today</node5>
                                                        > > </node1>
                                                        > >
                                                        > > The resulting JSON is going to be "ugly". Many added arrays
                                                        > > are added to handle the attributes and nested nodes now appear in the
                                                        > > added arrays. To me this adds a lot of extra complexity that I am
                                                        > > not sure I want.
                                                        > >
                                                        > >
                                                        > >
                                                        > > Best,
                                                        > > Mark Joseph, Ph.D.
                                                        > > P6R, Inc
                                                        > >
                                                        >
                                                        >
                                                        >
                                                        >
                                                        > [Non-text portions of this message have been removed]
                                                        >
                                                      • Fredag_d13
                                                        That looks pretty perfect to me. I think I will include JSONML support in the next release of my JSON api. Thanks to Mark Joseph for starting this discussion
                                                        Message 27 of 28 , Apr 7 1:25 AM
                                                        • 0 Attachment
                                                          That looks pretty perfect to me. I think I will include JSONML support in the next release of my JSON api.

                                                          Thanks to Mark Joseph for starting this discussion and thank you Stephen for the JSONML pointer.

                                                          I like the idea that no special characters such as @, # or stringpatterns are needed.

                                                          /Jonas

                                                          --- In json@yahoogroups.com, "stephen.mckamey" <stephen@...> wrote:
                                                          >
                                                          > Exactly. We were posting very similar examples at the same time. :)
                                                          >
                                                          > --- In json@yahoogroups.com, "Mark Joseph" <mark@> wrote:
                                                          > >
                                                          > > Ok I think I see how mixed content works in JsonML:
                                                          > >
                                                          > > <description lang="en-us"> hi there <bold>joe</bold> how are you </descrption>
                                                          > >
                                                          > > becomes
                                                          > >
                                                          > > [ "description", {"lang":"en-us"},
                                                          > > " hi there ",
                                                          > > [ "bold", "joe" ],
                                                          > > " how are you "
                                                          > > ]
                                                          > >
                                                          > > Is that right?
                                                          > >
                                                          > >
                                                          > > Best,
                                                          > >
                                                          > > Mark Joseph, Ph.D.
                                                          > > President
                                                          > > P6R, Inc
                                                          > > 408-205-0361
                                                          > > mark@
                                                          > > Skype: markjoseph_sc
                                                          > > _____
                                                          > >
                                                          > > From: stephen.mckamey [mailto:stephen@]
                                                          > > To: json@yahoogroups.com
                                                          > > Sent: Tue, 06 Apr 2010 10:20:12 -0700
                                                          > > Subject: Re: SV: [json] JSON representation for XML snippet
                                                          > >
                                                          > >
                                                          > >
                                                          > >
                                                          > >
                                                          > >
                                                          > > Not that ugly:
                                                          > >
                                                          > > ["node1", {"a":"45"},
                                                          > > ["node2", {"b":"9", "c":"hithere"},
                                                          > > ["node3", {"d":"abc"},
                                                          > > ["node4", {"e":"12345"}, "JSON has no attributes"]
                                                          > > ]
                                                          > > ],
                                                          > > "Now is the time for all good men to come to the aid of their party",
                                                          > >
                                                          > > ["node5", {"d":"45"}, "temperature is 70 degrees today"]
                                                          > > ]
                                                          > >
                                                          > > --- In json@yahoogroups.com, "Mark Joseph" <mark@> wrote:
                                                          > > >
                                                          > > >
                                                          > > > Handling XML attributes when converting to JSON:
                                                          > > > **************************************
                                                          > > > <attribute a2="v2">value2</attribute>
                                                          > > > will be
                                                          > > > {"attribute":{"a2":"v2"},"#text":"value2"}
                                                          > > >
                                                          > > > as example ... while JSONML uses this kind of schema
                                                          > > >
                                                          > > > ["nodeName",{"a2":"v2"},"text or nested nodes"]
                                                          > > >
                                                          > > > so that this:
                                                          > > >
                                                          > > > <attributes>
                                                          > > > <attribute a2="v2">value2</attribute>
                                                          > > > </attributes>
                                                          > > >
                                                          > > > will be this
                                                          > > >
                                                          > > > ["attributes",{},["attribute",{"a2":"v2"},"value2"]]
                                                          > > > ****************************************
                                                          > > >
                                                          > > > So all of the above works well when you have simple XML.
                                                          > > > But with something like:
                                                          > > >
                                                          > > > <node1 a="45">
                                                          > > > <node2 b="9" c="hithere">
                                                          > > > <node3 d="abc">
                                                          > > > <node4 e="12345">JSON has no attributes</node4>
                                                          > > > </node3>
                                                          > > > </node2>
                                                          > > > Now is the time for all good men to come to the aid of their party
                                                          > > >
                                                          > > > <node5 d="45">temperature is 70 degrees today</node5>
                                                          > > > </node1>
                                                          > > >
                                                          > > > The resulting JSON is going to be "ugly". Many added arrays
                                                          > > > are added to handle the attributes and nested nodes now appear in the
                                                          > > > added arrays. To me this adds a lot of extra complexity that I am
                                                          > > > not sure I want.
                                                          > > >
                                                          > > >
                                                          > > >
                                                          > > > Best,
                                                          > > > Mark Joseph, Ph.D.
                                                          > > > P6R, Inc
                                                          > > >
                                                          > >
                                                          > >
                                                          > >
                                                          > >
                                                          > > [Non-text portions of this message have been removed]
                                                          > >
                                                          >
                                                        • Mark Joseph
                                                          We have also decided to support JsonML in our next product version Sent from my iPhone ... [Non-text portions of this message have been removed]
                                                          Message 28 of 28 , Apr 7 4:11 AM
                                                          • 0 Attachment
                                                            We have also decided to support JsonML in
                                                            our next product version


                                                            Sent from my iPhone

                                                            On Apr 7, 2010, at 1:29 AM, "Fredag_d13" <jonas@...> wrote:

                                                            > That looks pretty perfect to me. I think I will include JSONML
                                                            > support in the next release of my JSON api.
                                                            >
                                                            > Thanks to Mark Joseph for starting this discussion and thank you
                                                            > Stephen for the JSONML pointer.
                                                            >
                                                            > I like the idea that no special characters such as @, # or
                                                            > stringpatterns are needed.
                                                            >
                                                            > /Jonas
                                                            >
                                                            > --- In json@yahoogroups.com, "stephen.mckamey" <stephen@...> wrote:
                                                            > >
                                                            > > Exactly. We were posting very similar examples at the same time. :)
                                                            > >
                                                            > > --- In json@yahoogroups.com, "Mark Joseph" <mark@> wrote:
                                                            > > >
                                                            > > > Ok I think I see how mixed content works in JsonML:
                                                            > > >
                                                            > > > <description lang="en-us"> hi there <bold>joe</bold> how are you
                                                            > </descrption>
                                                            > > >
                                                            > > > becomes
                                                            > > >
                                                            > > > [ "description", {"lang":"en-us"},
                                                            > > > " hi there ",
                                                            > > > [ "bold", "joe" ],
                                                            > > > " how are you "
                                                            > > > ]
                                                            > > >
                                                            > > > Is that right?
                                                            > > >
                                                            > > >
                                                            > > > Best,
                                                            > > >
                                                            > > > Mark Joseph, Ph.D.
                                                            > > > President
                                                            > > > P6R, Inc
                                                            > > > 408-205-0361
                                                            > > > mark@
                                                            > > > Skype: markjoseph_sc
                                                            > > > _____
                                                            > > >
                                                            > > > From: stephen.mckamey [mailto:stephen@]
                                                            > > > To: json@yahoogroups.com
                                                            > > > Sent: Tue, 06 Apr 2010 10:20:12 -0700
                                                            > > > Subject: Re: SV: [json] JSON representation for XML snippet
                                                            > > >
                                                            > > >
                                                            > > >
                                                            > > >
                                                            > > >
                                                            > > >
                                                            > > > Not that ugly:
                                                            > > >
                                                            > > > ["node1", {"a":"45"},
                                                            > > > ["node2", {"b":"9", "c":"hithere"},
                                                            > > > ["node3", {"d":"abc"},
                                                            > > > ["node4", {"e":"12345"}, "JSON has no attributes"]
                                                            > > > ]
                                                            > > > ],
                                                            > > > "Now is the time for all good men to come to the aid of their
                                                            > party",
                                                            > > >
                                                            > > > ["node5", {"d":"45"}, "temperature is 70 degrees today"]
                                                            > > > ]
                                                            > > >
                                                            > > > --- In json@yahoogroups.com, "Mark Joseph" <mark@> wrote:
                                                            > > > >
                                                            > > > >
                                                            > > > > Handling XML attributes when converting to JSON:
                                                            > > > > **************************************
                                                            > > > > <attribute a2="v2">value2</attribute>
                                                            > > > > will be
                                                            > > > > {"attribute":{"a2":"v2"},"#text":"value2"}
                                                            > > > >
                                                            > > > > as example ... while JSONML uses this kind of schema
                                                            > > > >
                                                            > > > > ["nodeName",{"a2":"v2"},"text or nested nodes"]
                                                            > > > >
                                                            > > > > so that this:
                                                            > > > >
                                                            > > > > <attributes>
                                                            > > > > <attribute a2="v2">value2</attribute>
                                                            > > > > </attributes>
                                                            > > > >
                                                            > > > > will be this
                                                            > > > >
                                                            > > > > ["attributes",{},["attribute",{"a2":"v2"},"value2"]]
                                                            > > > > ****************************************
                                                            > > > >
                                                            > > > > So all of the above works well when you have simple XML.
                                                            > > > > But with something like:
                                                            > > > >
                                                            > > > > <node1 a="45">
                                                            > > > > <node2 b="9" c="hithere">
                                                            > > > > <node3 d="abc">
                                                            > > > > <node4 e="12345">JSON has no attributes</node4>
                                                            > > > > </node3>
                                                            > > > > </node2>
                                                            > > > > Now is the time for all good men to come to the aid of their
                                                            > party
                                                            > > > >
                                                            > > > > <node5 d="45">temperature is 70 degrees today</node5>
                                                            > > > > </node1>
                                                            > > > >
                                                            > > > > The resulting JSON is going to be "ugly". Many added arrays
                                                            > > > > are added to handle the attributes and nested nodes now appear
                                                            > in the
                                                            > > > > added arrays. To me this adds a lot of extra complexity that I
                                                            > am
                                                            > > > > not sure I want.
                                                            > > > >
                                                            > > > >
                                                            > > > >
                                                            > > > > Best,
                                                            > > > > Mark Joseph, Ph.D.
                                                            > > > > P6R, Inc
                                                            > > > >
                                                            > > >
                                                            > > >
                                                            > > >
                                                            > > >
                                                            > > > [Non-text portions of this message have been removed]
                                                            > > >
                                                            > >
                                                            >
                                                            >


                                                            [Non-text portions of this message have been removed]
                                                          Your message has been successfully submitted and would be delivered to recipients shortly.