JSFiddle - React, Tailwind, and code Playground
JavaScript
require(["dojox/json/ref"], function() {
function arm(pobj) {
return {
id : pobj.idl,
parent : pobj.parent,
otherChar : pobj.otherChar
};
}
function leg(pobj) {
return {
id : pobj.id,
parent : pobj.parent,
otherChar : pobj.otherChar
};
}
function person(pobj) {
var p = {
id : pobj.id,
parent : pobj.parent,
otherChar : pobj.otherChar,
Arms : [],
Legs : []
};
p.Arms[p.Arms.length] = arm({
id: 1,
parent: p,
otherChar: "First"
});
p.Arms[p.Arms.length] = arm({
id: 2,
parent: p,
otherChar: "Second"
});
p.Legs[p.Legs.length] = leg({
id: 1,
parent: p,
otherChar: "First"
});
p.Legs[p.Legs.length] = leg({
id: 1,
parent: p,
otherChar: "Second"
});
return p;
}
var group = [];
group[group.length] = person({
id: 1,
parent: null,
otherChar: "first"
});
group[group.length] = person({
id: 2,
parent: null,
otherChar: "second"
});
var jsonMe = dojox.json.ref.toJson(group); // serialize me
alert(jsonMe);
});