Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8199889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:15:50+00:00 2026-06-07T06:15:50+00:00

I am trying to convert Javascript object to CSV and store it in to

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:15:51+00:00Added an answer on June 7, 2026 at 6:15 am

    That’s a pretty deep structure, but this function will work with your data as-is. The fixSpace() function accounts for the discrepancy between Dec 9 and Dec_9.

    Demo: http://jsfiddle.net/ThinkingStiff/r2kje/

    Output:

    News:
    "http://www.testingmyurl.com","News","Germany","Election"
    "http://www.testingmyurl.com","News","Egypt","Revolution"
    Time:
    "http://www.testingmyurl.com","Time","Dec 9","2012"
    

    Script:

    function findProps( name, data ) {
        var results = [],
            events = data._source.Categories.Types.Events,
            link = data._source.link;
    
        for( var eventIndex = 0; eventIndex < events.length; eventIndex++ ) {
            var event = events[eventIndex];
            if( event.entity == name && event[name]  ) {
                for( var entityIndex = 0; entityIndex < event[name].length; entityIndex++ ) {
                    var entity = event[name][entityIndex],
                        entityName = fixSpace( entity.entity );
                    if( entity[entityName] ) {
                        for( var valueIndex = 0; valueIndex < entity[entityName].length; valueIndex++ ) {
                            var value = entity[entityName][valueIndex];
                            results.push( 
                                  '"' + link + '",'
                                + '"' + name + '",'
                                + '"' + entity.entity + '",' //un-fixSpaced name
                                + '"' + value.entity + '"'
                            );
                        };
                    };
                };
            };
        };
    
        return results;
    };
    
    function fixSpace( value ) {
        return value.replace( ' ', '_' );        
    };
    
    var news = findProps( "News", data );
    document.getElementById( 'news' ).innerHTML = news.join( '<br />' );
    var times = findProps( "Time", data );
    document.getElementById( 'time' ).innerHTML = times.join( '<br />' );
    

    HTML:

    News:
    <div id="news"></div>
    Time:
    <div id="time"></div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to pass a javascript Date object to a controller that I have
I'm trying to modify this example http://storelocator.googlecode.com/git/examples/panel.html the javascript code is here: https://gist.github.com/2725336 the
I have a response object which I want to convert to Json, but somehow
I'm trying to use JavaScript to convert a date object into a valid MySQL
I'm trying to convert a delimited key/value string into an object in javascript and
I'm trying to convert an Object to String in JavaScript to do some String
Background : I'm trying to convert some JavaScript code which uses the the Crossfilter
I am trying to convert some pre-existing html/JavaScript files to Flex. I tried making
I'm trying to convert the following jquery to javascript syntax, but being not familiar
I'm trying to convert date formats in javascript. I get a string from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.