{
"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.
"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. 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:
%dw 2.0
output application/csv
---
payload.one.four.five
Output (after removing the extra double quote in line 17 of the input):
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:
%dw 2.0
output application/csv
---
payload.one.four.five
map (item, index) -> {five: item.five as String {format: "yyyy-MM-dd"}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.