Skip to content
Advertisement

How to process object with map for CSV output

I have a set of below Objects, which i need to write to CSV:

JavaScript

Above set can have a map with two, three or four values.

JavaScript

Output of CSV required:

JavaScript

I started with below snippet to print out:

JavaScript

But above is creating a two column csv with userId and behaviours printing all map object behaviours. How to achieve above type of output.

As the set may contain huge number of such objects, how can this be done efficiently.

Advertisement

Answer

Using JSONArray seems to be redundant here, you could implement a helper method to serialize OutputObject into a CSV string, taking into account that the order of the columns needs to be maintained:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement