Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fLoopThrough ( obj, parent, thirdLevel ) {
- $.each( obj , function ( index, sValue ) {
- if (typeof sValue !== 'object' && !$.isArray(sValue)) {
- if (!parent && !thirdLevel ) {
- var oReformat = {text : index, value : sValue};
- newObj.push(oReformat);
- } else if (parent && !thirdLevel ) {
- var oReformat = {text : index, value : sValue};
- newObj[parent].push(oReformat);
- } else if (thirdLevel) {
- var oReformat = {text : index, value : sValue};
- newObj[thirdLevel][parent].push(oReformat);
- }
- } else if (typeof sValue == 'object' && !$.isArray(sValue)) {
- if (!parent) {
- newObj[index] = new Array();
- } else if (parent) {
- newObj[parent][index] = new Array();
- thirdLevel = parent;
- }
- fLoopThrough(sValue, index, parent);
- }
- })
- return newObj;
- }
- var newObj = [];
- var oReformattedJSON = fLoopThrough(yourJSON);
- console.log('oReformattedJSON...',oReformattedJSON);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement