Advertisement
Guest User

Untitled

a guest
May 29th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. function fLoopThrough ( obj, parent, thirdLevel ) {
  2. $.each( obj , function ( index, sValue ) {
  3. if (typeof sValue !== 'object' && !$.isArray(sValue)) {
  4. if (!parent && !thirdLevel ) {
  5. var oReformat = {text : index, value : sValue};
  6. newObj.push(oReformat);
  7. } else if (parent && !thirdLevel ) {
  8. var oReformat = {text : index, value : sValue};
  9. newObj[parent].push(oReformat);
  10. } else if (thirdLevel) {
  11. var oReformat = {text : index, value : sValue};
  12. newObj[thirdLevel][parent].push(oReformat);
  13. }
  14. } else if (typeof sValue == 'object' && !$.isArray(sValue)) {
  15. if (!parent) {
  16. newObj[index] = new Array();
  17. } else if (parent) {
  18. newObj[parent][index] = new Array();
  19. thirdLevel = parent;
  20. }
  21. fLoopThrough(sValue, index, parent);
  22. }
  23. })
  24. return newObj;
  25. }
  26.  
  27. var newObj = [];
  28. var oReformattedJSON = fLoopThrough(yourJSON);
  29.  
  30. console.log('oReformattedJSON...',oReformattedJSON);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement