嵌套的JSON转换为CSV Dataweave


{
"one": {
"two": [
"199052",
"109926"


],
"three": [
"191",
"190",
"189",
"188",
"187"

],
"four": {
"five": [
{
"five": "2022-03-24"
},
{
"five": "2022-03-24"
},
{
"five": "2022-03-18"
},
{
"five": "2022-03-18"
},
{
"five": "2022-03-18"
},
{
"five": "2022-03-14"
},
{
"five": "2022-03-14"
},

],
"six": {
"seven": [
"Test1",
"Test2",
"Test1",
"Test2"

],
"eight": [
"first description.",
"second description",
"first description.",
"second description"

]
},
"nine": {
"name": [
"Ps3564",
"35355Ps"



]
},
"tenCreated": [

{
"tenCreated": "2022-02-10"
},
{
"tenCreated": "2022-02-10"
},
{
"tenCreated": "2022-02-10"
}
],
"elevenUpdated": [
{
"elevenUpdated": "2022-03-24"
},
{
"elevenUpdated": "2022-03-24"
},
{
"elevenUpdated": "2022-03-24"
},
],
"twelve": {
"thirteen": [
"fourteen",
"Do",
"Do again",
"Do work",
"Doone"
]
},
"fifteen": {
"name": [
"Good",
"Not good",
"good"

]
},
"sixteen": {
"sixteenCreator": [
"Jan Kowalski",
"Jan kowalski",
"Jan Kowalski",
"Jan kowalski"

],
"seventeen": null
},
"eieighteen": [
"Test test",
"test test 10",
"api test",



],
"ninteen": {
"ninteeneReporter": [
"Jan Kowalski",
"Jan Kowalski",
"Jan Kowalski"


],
"twentyEmail": [
"jankowalski@",
"jankowalski@"

]
},
"twentyOne": {
"TwentyTwo": [
"Jan Kowalski",
"Jan Kowalski",
"Jan Kowalski"


],
"TwnetyThree": [
"jankowalski@",
"jankowalski@"

]
},
"TwentyFour": {
"TwentyFive": [
"P186",
"P186",
"P186",

],
"TwentySix": {
"TwentySeven": [
"Plan",
"Plan",
"Plan"


],
"TwentyEight": [
"END",
"END"

],
"Thiry": [
"To Do",
"To Do",
"To Do",
"To Do",

],
"ThirtyOne": null
}
}
}
}
}

嗨,我有这个json,我想把它转换成CSV。这是我的转换DateTime,我做了这样的事情,但这段代码为每个日期提供了额外的标记。

"five": {
"five": payload.one.four.five map (item, index) -> {
five : item
as DateTime 
{format: "yyyy-MM-dd'T'HH:mm:ss.SSSxx"}
as String {format: "yyyy-MM-dd"} }

但我对这些数据的输出是这样的。只有日期。是否可以像我一样在不改变结构的情况下更改日期?


"five": [
"2022-03-24T15:17:46.846+0100",
"2022-03-24T09:05:35.133+0100",
"2022-03-24T09:06:12.081+0100",

],

如果您的预期输出是一个只有five列下日期的CSV,那么您可以选择它:

%dw 2.0
output application/csv
---
payload.one.four.five 

输出(删除输入第17行中多余的双引号后(:

five
2022-03-24
2022-03-24
2022-03-18
2022-03-18
2022-03-18
2022-03-14
2022-03-14

如果你想对数据进行额外的转换,你可以根据需要映射数组的每个元素:

%dw 2.0
output application/csv
---
payload.one.four.five 
map (item, index) -> {five: item.five as String {format: "yyyy-MM-dd"}}

相关内容

  • 没有找到相关文章

最新更新