Monday, February 6th, 2006
Transforming JSON
<p>Stefan Gössner has seen a need to transform the JSON format, similarly how we transform XML via XSLT.The implementation of JSON/T is by writing rules in JSON format itself.
Example
Given a JSON object such as:
-
-
{ "link": {"uri":"http://company.com", "title":"company homepage" }}
-
and transform it to:
The JSON/T rule for doing this:
-
-
{ "link": "<a href="{link.uri}">{link.title}</a>" }
-
You can download a JavaScript version of the JSON/T processor
Related Content:











It’s funny how the JSON/T rule looks different in my feed reader than on this page. In my feed reader it did not make sense, but here it does.
In a similar vein, I wrote a json2dom script about a week ago. I don’t know if it has any practical application (probably not), but I wanted a way to create HTML elements from an Ajax response without using innerHTML, and this is what I came up with.
[...] I first read about this over on Ajaxian and Randy Boland commented to say that he’s done a JSON to DOM script as well. [...]
One major different between XSLT and a JSON transformer is that the later need to have a grammar for object/hash enumeration, I wonder whether JSONT support it, which I found lost in many js template engine.