- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
Sorting nested array with a specific list with dataweave
Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram: https://www.instagram.com/ky.emrah
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Sorting nested array with a specific list with dataweave
Sorting an array is correct, but result is not correct with a nested array.
I tried with a simple array, output is correctly sorted.
%dw 2.0
output application/json
import indexOf from dw::core::Arrays
var sortOrder=["P_A", "P_B"]
var myInput=[
{
"product": "P_B",
"price": 12
},
{
"product": "P_A",
"price": 21
}
]
---
myInput orderBy( indexOf(sortOrder, $.product))
%dw 2.0
output application/json
import indexOf from dw::core::Arrays
var sortOrder=["P_A", "P_B"]
var myInput=[
{
"product": "P_B",
"price": 12
},
{
"product": "P_A",
"price": 21
}
]
---
myInput orderBy( indexOf(sortOrder, $.product))
Output is:
[
{
"product": "P_A",
"price": 21
},
{
"product": "P_B",
"price": 12
}
]
[
{
"product": "P_A",
"price": 21
},
{
"product": "P_B",
"price": 12
}
]
But when trying with a nested array, output is not sorted at all.
%dw 2.0
output application/json
import indexOf from dw::core::Arrays
var sortOrder=["P_A", "P_B"]
var myInput=[
{
"command": "AZ59696",
"products": [
{
"product": "P_B",
"price": 12
},
{
"product": "P_A",
"price": 21
}
]
},
{
"command": "BA23122",
"products": [
{
"product_ref": "P_A",
"price": 21
},
{
"product_ref": "P_B",
"price": 12
}
]
}
]
---
myInput map ((item, index) - item update {
case .item.products - item.products orderBy( indexOf(sortOrder, $.product))
})
%dw 2.0
output application/json
import indexOf from dw::core::Arrays
var sortOrder=["P_A", "P_B"]
var myInput=[
{
"command": "AZ59696",
"products": [
{
"product": "P_B",
"price": 12
},
{
"product": "P_A",
"price": 21
}
]
},
{
"command": "BA23122",
"products": [
{
"product_ref": "P_A",
"price": 21
},
{
"product_ref": "P_B",
"price": 12
}
]
}
]
---
myInput map ((item, index) - item update {
case .item.products - item.products orderBy( indexOf(sortOrder, $.product))
})
The output is:
[
{
"command": "AZV59696",
"products": [
{
"product": "P_B",
"price": 12
},
{
"product": "P_A",
"price": 21
}
]
},
{
"command": "BA2322",
"products": [
{
"product_ref": "P_A",
"price": 21
},
{
"product_ref": "P_B",
"price": 12
}
]
}
]
[
{
"command": "AZV59696",
"products": [
{
"product": "P_B",
"price": 12
},
{
"product": "P_A",
"price": 21
}
]
},
{
"command": "BA2322",
"products": [
{
"product_ref": "P_A",
"price": 21
},
{
"product_ref": "P_B",
"price": 12
}
]
}
]
What's wrong?Source of the question:
https://stackoverflow.com/questions/78988511
Question and source license information:
https://meta.stackexchange.com/help/licensing
https://stackoverflow.com/
Видео Sorting nested array with a specific list with dataweave канала Emrah KAYA
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!Sorting nested array with a specific list with dataweave
Sorting an array is correct, but result is not correct with a nested array.
I tried with a simple array, output is correctly sorted.
%dw 2.0
output application/json
import indexOf from dw::core::Arrays
var sortOrder=["P_A", "P_B"]
var myInput=[
{
"product": "P_B",
"price": 12
},
{
"product": "P_A",
"price": 21
}
]
---
myInput orderBy( indexOf(sortOrder, $.product))
%dw 2.0
output application/json
import indexOf from dw::core::Arrays
var sortOrder=["P_A", "P_B"]
var myInput=[
{
"product": "P_B",
"price": 12
},
{
"product": "P_A",
"price": 21
}
]
---
myInput orderBy( indexOf(sortOrder, $.product))
Output is:
[
{
"product": "P_A",
"price": 21
},
{
"product": "P_B",
"price": 12
}
]
[
{
"product": "P_A",
"price": 21
},
{
"product": "P_B",
"price": 12
}
]
But when trying with a nested array, output is not sorted at all.
%dw 2.0
output application/json
import indexOf from dw::core::Arrays
var sortOrder=["P_A", "P_B"]
var myInput=[
{
"command": "AZ59696",
"products": [
{
"product": "P_B",
"price": 12
},
{
"product": "P_A",
"price": 21
}
]
},
{
"command": "BA23122",
"products": [
{
"product_ref": "P_A",
"price": 21
},
{
"product_ref": "P_B",
"price": 12
}
]
}
]
---
myInput map ((item, index) - item update {
case .item.products - item.products orderBy( indexOf(sortOrder, $.product))
})
%dw 2.0
output application/json
import indexOf from dw::core::Arrays
var sortOrder=["P_A", "P_B"]
var myInput=[
{
"command": "AZ59696",
"products": [
{
"product": "P_B",
"price": 12
},
{
"product": "P_A",
"price": 21
}
]
},
{
"command": "BA23122",
"products": [
{
"product_ref": "P_A",
"price": 21
},
{
"product_ref": "P_B",
"price": 12
}
]
}
]
---
myInput map ((item, index) - item update {
case .item.products - item.products orderBy( indexOf(sortOrder, $.product))
})
The output is:
[
{
"command": "AZV59696",
"products": [
{
"product": "P_B",
"price": 12
},
{
"product": "P_A",
"price": 21
}
]
},
{
"command": "BA2322",
"products": [
{
"product_ref": "P_A",
"price": 21
},
{
"product_ref": "P_B",
"price": 12
}
]
}
]
[
{
"command": "AZV59696",
"products": [
{
"product": "P_B",
"price": 12
},
{
"product": "P_A",
"price": 21
}
]
},
{
"command": "BA2322",
"products": [
{
"product_ref": "P_A",
"price": 21
},
{
"product_ref": "P_B",
"price": 12
}
]
}
]
What's wrong?Source of the question:
https://stackoverflow.com/questions/78988511
Question and source license information:
https://meta.stackexchange.com/help/licensing
https://stackoverflow.com/
Видео Sorting nested array with a specific list with dataweave канала Emrah KAYA
Комментарии отсутствуют
Информация о видео
19 марта 2025 г. 15:23:22
00:01:18
Другие видео канала
