[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XSLT functions for JSON

Subject: XSLT functions for JSON
From: "Jesper Tverskov" <jesper@xxxxxxxxxxx>
Date: Sun, 18 May 2008 15:52:35 +0200
 XSLT functions for JSON
I think we need three XSLT functions for JSON.

As I have found out from the "XSL in the AJAX world" thread,
there are several issues in xml2json transformation and in json2xml

1. As seen from Google's use of JSON,
and from Stefan Goessner's article, Converting Between XML and JSON,
property names in JSON could begin with characters not allowed as
first character in XML like "$" (used by Goggle) and "@", and "#" used
by article. I find it strange but not surprising that even in JSON
only "$" works in both IE7 and Firefox. "@" only works in Firefox, and
"#" not even in Firefox!

The bottom line is: some characters are allowed as first character in
JSON but not in XML making even the most simple json2xml
transformation problematic:  the maker of the function must find a way
to deal with illegal characters in XML.

2. JSON has no way of handling even the most simple document oriented
XML structure like: "h2, p, h2, p" if the order matters as is likely
in the example. In JSON the order of the example will be changed to:
"h2, h2, p, p".

3. JSON has no standardized way of handling attributes. Attributes
will most likely be converted to what could just as well have been an
element or some prefix character will be added signaling that this was
originally an attribute. This prefix depends on who made the
conversion function, making it impossible to convert back unless a
similar function is used understanding the meaning of the prefix

4. JSON has no standardized way of handling mixed content.
Theoretically the most simple mixed content could be handled with a
method similar to handling attributes but the prefix characters needed
to tell text and element apart depends on who made the function. If
mixed content consists of more than one text node and one element we
run into the reordering problem.

In XSLT I see the need for three JSON functions:

1. We need a "standalone" json2xml function. If  first characters are
used in JSON not legal in XML, or if other constructs that cannot be
converted to XML (?) is used, it must abort. For first character it
must be possible to use the function with a parameter solving the
first character issue changing it to something legal.

2.  We need a pair of xml2json and json2xml functions that can
transform back and forth. The xml2json function must abort if
reordering of elements becomes necessary or if mixed content is
detected. Many things in the XML document will of cause be lost: XML
Declaration, DOCTYPE, PIs and comments. If reordering of elements is
not a problem it must be possible to use some parameter making the
transformation successful.

Jesper Tverskov

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.