Created
April 2, 2012 13:28
-
-
Save chris-held/2283415 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function jsonToCSV(json) | |
{ | |
var jsonobject = typeof json != 'object' ? JSON.parse(json) : json; | |
var str = ''; | |
for (var key in jsonobject) { | |
var line = ''; | |
var obj = jsonobject[key]; | |
for (var prop in obj) { | |
if(typeof obj[prop] == "object"){ | |
jsonToCSV(obj[prop]); | |
} else { | |
line += prop + " : " + obj[prop] + ','; | |
} | |
} | |
line.slice(0,line.Length-1); | |
str += line + '\r\n'; | |
} | |
//window.open( "data:text/csv;charset=utf-8," + escape(str)) | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment