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

Re: Where our JSON product is heading: XML to JSON and Back

Expand Messages
  • 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 1 of 28 , Apr 6, 2010
    • 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 2 of 28 , Apr 6, 2010
      • 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 3 of 28 , Apr 7, 2010
        • 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 4 of 28 , Apr 7, 2010
          • 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.