Export nested objects from an AngularJS JSON array to a CSV file

When I download my data into a CSV file, the display setting is showing as "[object Object]". This is not the desired outcome.

https://i.stack.imgur.com/ej2UO.png

The expected display should look like this:

https://i.stack.imgur.com/8JJ88.png

This is part of my JavaScript code:

  $scope.download = function () {
    var csv = jsonToCsv(['ThemeName', 'DataSharing', 
   'DisplaySetting', 'ExpiryDate', 'Icon', 
   'PublishDate','QueryName','ThemeName', 'ThemeOwner'], health)
    var csvBlob = new Blob([csv], { type: 'text/csv' });
    saveAs(csvBlob, 'json.csv');
    };

Could someone please advise on how to modify this code to display the object correctly in the CSV file? Is there a way to customize which objects are displayed in the CSV file?

I would be grateful for any assistance or guidance. I am open to changing my coding approach if it leads to a solution. Any recommended resources would also be highly appreciated. Thank you!

Here is an example of using JSON.stringify:

   else if ($scope.all[i].CATEGORY == 'Health')
  {
     health.DISPLAY_SETTING = 
     JSON.stringify(health.DISPLAY_SETTING)
     health.push($scope.all[i]);
  }

Answer №1

One way to approach this is by using the JSON.stringify() method on the DisplaySetting property within the health object before attempting to convert it to a CSV format:

health.DisplaySetting = JSON.stringify(health.DisplaySetting);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Traverse Through Collection of Vue Elements

I am working on creating an array of Vue Components based on a configuration file containing various UI sections to display; const config = [ 'summarySection', 'scoreSection', 'educationSection' ] I am attempting to ma ...

What steps should I take to host my Vue js single page application on my Django server?

At present, I am in the process of following a tutorial to integrate my Vue.js frontend with my Django backend. You can find the guide here: https://medium.com/@williamgnlee/simple-integrated-django-vue-js-web-application-configured-for-heroku-deployment-c ...

Ajax received a response from http 409 and is now parsing it

Hey there! I've been working on parsing out the message object using Ajax, and I'm having a bit of trouble getting a reference to messages.msg. It's strange because it displays perfectly fine in Postman, but for some reason, I can't see ...

Having trouble getting Video.js SWF to work on Internet Explorer?

I've been working with video.js and am having trouble getting it to function properly on Internet Explorer. I have added the swf file like this: videojs.options.flash.swf = "http://vjs.zencdn.net/4.2/video-js.swf " Here is the code for the video pla ...

Is it possible that the use of excessive React.Fragment could impact performance negatively?

After a recent review of our company's code, I discovered that the performance is not up to par. One common pattern I noticed in the code is something like this: condition ? <SomeComponent /> : <></> I see that Fragments are being u ...

Issue with thymeleaf causing malfunction in top-bar navigation on foundation framework

Looking for advice on creating a navigable menu using Foundation's "top-bar" component in an HTML template file with Spring MVC + thymeleaf. The menu bar appears but the sub-menus are not displaying when hovering over them. Sub-menus related to main ...

Access a specific JSON value using AngularJS

When using AngularJS to read a specific JSON value, I encountered the following issue: $http({method: 'GET', url: urlVersion}). success(function(data, status, headers, config) { console.log("success data " + status); $scope.ext = data.ve ...

Splitting content into separate paragraphs using AngularJS helps organize information more effectively

I received the information from a json file using $http.get('json/about.json').success(function($scope.about = data;} For example, the data includes: Hello there paragraph. How are you doing paragraph. What's up paragraph. My goal is to s ...

Creating a dynamic user list display feature in AngularJS similar to WhatsApp's user textbox feature

I am looking to display a list of users when a user presses the @ button in a text box, similar to how WhatsApp shows group members in AngularJS. Here is my html code: <input class="nostyle search-filter" ng-model="searchUsers" type="text" placeholde ...

What is the best way to bring in a variable initialized by an IIFE from a JavaScript file into a TypeScript class?

I'm currently working towards integrating the steelseries.js library (found at https://github.com/HanSolo/SteelSeries-Canvas) into a Grafana plugin built with React. It's quite a complex task, but I'm up for the challenge. Right now, my ma ...

Is it possible to utilize a single controller for multiple views?

I have set up a single controller and utilized it in two views with minor variations. Here is the Angular code snippet: app.controller('MyCtrl', function($scope) { $scope.canSave = false; $scope.demo = { files : [{ filename ...

"Troubleshooting: Ajax error 'Uncaught ReferenceError: data is not defined' on the

Upon checking the Chrome console, the error message displayed is : Uncaught ReferenceError: data is not defined function list(){ $.ajax({ type:'POST', url:'adeneme.php', data:$('#form1').seri ...

Sending emails with attachments using the power of AngularJS and Java Spring

I have an email sender that works perfectly fine, but it lacks attachment functionality. I attempted the following solution: Here is a simple HTML input: <input type="file" simple-change="uploadFiles($event)"/> This is the JavaScript file picker: ...

Is there a way to verify whether a user is currently logged in? (Using everyauth in node.js)

Previously, I relied on client-side auth for my application. Recently, I integrated server-side everyauth and it's functioning well. However, I'm unsure how to perform a function similar to FB.getLoginStatus (which I used in the client-side) when ...

"Encountering an issue with AngularJS: Want to use bindToController with a required controller, but

In one of my directives, I am utilizing the require and bindToController properties in the definition. (function(){ 'use strict'; angular.module('core') .directive('formValidationManager', formValidationManag ...

What is the best method for implementing click functionality to elements that share a common class using only pure JavaScript

I am struggling to figure out how to select specific elements with the same classes using only pure JavaScript (no jQuery). For example: <div class="item"> <div class="divInside"></div> </div> <div class= ...

When attempting to connect to the MongoDB cloud, an unexpected error arises that was not present in previous attempts

npm start > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="650800170b4816001713001725544b554b55">[email protected]</a> start > nodemon index.js [nodemon] 3.0.2 [nodemon] to restart at any time, enter ...

Issue encountered while trying to execute Reapp project demo

As I embark on setting up my initial Reapp project, I encounter a roadblock right at the start. A blank screen greets me, accompanied by a console error stating that main.js is not found (error 404). Upon executing reapp run -d, the following errors manif ...

How can I retrieve and process a text or .csv file that has been uploaded using Multer?

Just starting out with Multer - I created an application to analyze a .csv file and determine the frequency of each keyword and phrase in the document. However, I have since made adjustments using node and express to analyse the file AFTER it has been subm ...

Cookies are mysteriously invisible in the developer console of Safari/Chrome when using the Set-Cookie Header, yet they miraculously appear in server logs

Storing cookies for my web app using the 'Set-Cookie' header response from my python backend has been a challenge. https://i.stack.imgur.com/XMx35.png An ajax call on the client-end to the function is where I run into issues: https://i.stack.im ...