【问题】
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 vari

本文介绍了如何使用 SPL 语言处理动态生成的 JSON 数组,将其转换为 CSV 文件。在面临需要创建与 JSON 键值对数量相匹配的列,且键名未知的情况下,传统的 Java 或 GSON 方法由于无法动态生成类成员变量而显得不适用。SPL 提供了一种高效且简便的解决方案,可以轻松将此类不定结构的 JSON 数据写入 CSV 文件。
最低0.47元/天 解锁文章
686

被折叠的 条评论
为什么被折叠?



