3.2.06 # JSONT - Transforming JSON

In XML we can transform documents by another XML document containing transformation rules (XSLT) and applying these rules using an XSLT-processor.

Adopting that concept I have been experimenting with a set of transformation rules written in JSON.

Now in analogy to XML/XSLT the combination JSON/JSONT can be used to transform JSON data into any other format by applying a specific set of rules.

Read more ...

5 comments

I liked JSONT Standard, probably use it in one of my projects. But fixed two bugs I have encountered.

I have changed, "T.eval" method the following way. Added support Date object and fixed a bug for Array object. For example sometimes, Arrays appear as object in javascript so I'm checking the "sort" function for the object.

eval: function(expr) {
var v = eval(expr), res = "";
if (typeof(v) != "undefined") {
if (typeof v.sort == 'function' /*v instanceof Array*/) {
for (var i=0; i<v.length; i++)
if (typeof(v[i]) != "undefined")
res += T.apply(expr+"["+i+"]");
}
else if (typeof v.getTimezoneOffset == 'function' ) { //Date object
res += v;
}
else if (typeof(v) == "object") {
for (var m in v)
if (typeof(v[m]) != "undefined") {
res += T.apply(expr+"."+m);
}
}
else if (T.output)
res += v;
}
return res;
}
 

Hello. This tool seems to be a bit misleading. It does not transform JSON, it transforms Javascript objects. These are quite different things. JSON is a string, while an object is an actual object. If you pass this function a JSON string as data, it will not work!!
 

Are there any plans on making this more optimal? It uses eval tons... perhaps a better plan would be for jsont to take a rules object and transform it into a processor that then processes the object.

Another cool improvement would be for the array index to be available somewhere during the parse(right now I'm hacking it in). The reason for this is I am taking advantage of the fact that I can use arrays to compress some common data rather than repeating it.

If the repeated eval was adjusted, I think this would make it significantly more performant and attractive.
 

You might be interested in my comment on http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html?page=3 regarding the use of XSugar for performing bi-directional translations between XML and some other text-based format.

Robert
robertm is at ed ## ac ;; uk
 

I include you JSONT into JsonV format more please see on http://semanticfind.com/format-vlada/
 
Kommentar veröffentlichen