I am trying to convert Javascript object to CSV and store it in to a file.. I have a demo: http://jsbin.com/atewix/8/edit
What I want to do is If I give the entity values "Time" or "News" inside function findProps()
,
It should return CSV in the format:
"http://www.testingmyurl.com", Time, Dec 9, 2012
or
"http://www.testingmyurl.com",News, Germany,Election
"http://www.testingmyurl.com",News,Egypt, Revolution
with the current format it returns only individual values and that too as [object,object]
{
"_index": "test",
"_source": {
"link": "http://www.testingmyurl.com",
"Categories": {
"Types": {
"Events": [{
"count": 1,
"entity": "Time",
"Time": [{
"entity": "Dec 9",
"Dec_9": [{
"count": 1,
"entity": "2012"
}]
}]
}]}}}}
Can this be turned in to a flat structure?
That's a pretty deep structure, but this function will work with your data as-is. The
fixSpace()
function accounts for the discrepancy betweenDec 9
andDec_9
.Demo: http://jsfiddle.net/ThinkingStiff/r2kje/
Output:
Script:
HTML: