[英]Nested JSON convert to 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
}
}
}
}
}
Hi I have this json and I would like convert it to CSV. And here is my transform DateTime I did something like this but this code give me extra tag for each date.嗨,我有这个 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"} }
But my output for this data looks like this.但是我的这个数据的output是这样的。 There is only the DATE.只有日期。 It's a possible to change the DATE without change the structure like I did?是否可以像我一样更改日期而不更改结构?
"five": [
"2022-03-24T15:17:46.846+0100",
"2022-03-24T09:05:35.133+0100",
"2022-03-24T09:06:12.081+0100",
],
If your expected output is a CSV with only the dates under column five
then you could just select it:如果您预期的 output 是一个 CSV,只有five
列下的日期,那么您可以将它设为 select:
%dw 2.0
output application/csv
---
payload.one.four.five
Output (after removing the extra double quote in line 17 of the input): Output(在输入的第 17 行中删除多余的双引号后):
five
2022-03-24
2022-03-24
2022-03-18
2022-03-18
2022-03-18
2022-03-14
2022-03-14
If you want an extra transformation of the data, you can map each element of the array as needed:如果你想对数据进行额外的转换,你可以根据需要 map 数组的每个元素:
%dw 2.0
output application/csv
---
payload.one.four.five
map (item, index) -> {five: item.five as String {format: "yyyy-MM-dd"}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.