【问题】
I am trying to create a CSV file from a dynamically generated JSON array. For example:
“People” :
[{“name” : “Bob”, “age” : 5},
{“dob” : “5/2/4”, “name” : “Alice”},
{“name” : “George”}]
would create the csv file
name, age, dob
Bob, 5,
Alice, , 5/2/4
George, ,
As you can see, I need to create a column for every field in the JSON array. The order of each key-value pair in the JSON array is random. I also do not know name of the keys beforehand. Don’t worry about the “People” field, there will only be one array in each JSON. (This will most be the CSV name).
I have tried using theJackson CSV library but this requires me to create a pre-defined POJO as a middle tier (JSON -> POJO -> CSV). As far as I know, Java does not allow me to dynamically generate a class’ member variables at run time,