如何继承每个现有子M子4的父元素4

发布于 2025-01-23 05:04:11 字数 1748 浏览 0 评论 0原文

您需要为每个孩子的sku元素复制一系列父元素。

输入:

{
"items": [
    {
        "order": "ASD51247",
        "reference": "271559410",
        "date": "2022-04-01T22:58:19.077Z",
        "lines": [
            {
                "number": "6578523423489",
                "description": "ITEM 1"
            }
        ],
        "received": "2022-03-31T09:46:13.260Z",
        "created": "2022-03-31T09:46:13.109Z"
    },{
        "order": "AST927353",
        "reference": "271944522",
        "date": "2022-04-01T22:58:19.038Z",
        "lines": [
            {
                "number": "4563252696546",
                "description": "ITEM 2"
            },
            {
                "number": "890456234326",
                "description": "ITEM 3"
            }
        ],
        "received": "2022-03-31T10:25:08.508Z",
        "created": "2022-03-31T10:25:08.353Z"
    }
]}

预期输出:

{ "item":[
  {
     "order":"ASD51247",
     "reference":"271559410",
     "date":"2022-04-01T22:58:19.077Z",
     "number":"6578523423489",
     "description":"ITEM 1",
     "receivedAt":"2022-03-31T09:46:13.260Z",
     "createdAt":"2022-03-31T09:46:13.109Z"
  },
  {
     "order":"AST927353",
     "reference":"271944522",
     "date":"2022-04-01T22:58:19.038Z",
     "number":"4563252696546",
     "description":"ITEM 2",
     "received":"2022-03-31T10:25:08.508Z",
     "created":"2022-03-31T10:25:08.353Z"
  },
  {
     "order":"AST927353",
     "reference":"271944522",
     "date":"2022-04-01T22:58:19.038Z",
     "number":"890456234326",
     "description":"ITEM 3",
     "received":"2022-03-31T10:25:08.508Z",
     "created":"2022-03-31T10:25:08.353Z"
  }]}

在输出中,必须继承“线”数组中每个孩子的父元素。任何帮助将不胜感激。谢谢。

There is an array of parent elements that you need to duplicate for each child sku element you have.

Input:

{
"items": [
    {
        "order": "ASD51247",
        "reference": "271559410",
        "date": "2022-04-01T22:58:19.077Z",
        "lines": [
            {
                "number": "6578523423489",
                "description": "ITEM 1"
            }
        ],
        "received": "2022-03-31T09:46:13.260Z",
        "created": "2022-03-31T09:46:13.109Z"
    },{
        "order": "AST927353",
        "reference": "271944522",
        "date": "2022-04-01T22:58:19.038Z",
        "lines": [
            {
                "number": "4563252696546",
                "description": "ITEM 2"
            },
            {
                "number": "890456234326",
                "description": "ITEM 3"
            }
        ],
        "received": "2022-03-31T10:25:08.508Z",
        "created": "2022-03-31T10:25:08.353Z"
    }
]}

Expected Output:

{ "item":[
  {
     "order":"ASD51247",
     "reference":"271559410",
     "date":"2022-04-01T22:58:19.077Z",
     "number":"6578523423489",
     "description":"ITEM 1",
     "receivedAt":"2022-03-31T09:46:13.260Z",
     "createdAt":"2022-03-31T09:46:13.109Z"
  },
  {
     "order":"AST927353",
     "reference":"271944522",
     "date":"2022-04-01T22:58:19.038Z",
     "number":"4563252696546",
     "description":"ITEM 2",
     "received":"2022-03-31T10:25:08.508Z",
     "created":"2022-03-31T10:25:08.353Z"
  },
  {
     "order":"AST927353",
     "reference":"271944522",
     "date":"2022-04-01T22:58:19.038Z",
     "number":"890456234326",
     "description":"ITEM 3",
     "received":"2022-03-31T10:25:08.508Z",
     "created":"2022-03-31T10:25:08.353Z"
  }]}

In output, must be inherit the parent elements for each child in the "lines" array. Any help would be appreciated. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌上青苔 2025-01-30 05:04:11
%dw 2.0
output application/json
---
item: payload.items flatMap ((item, index) ->

        (item.lines map {
       order: item.order,
       reference:item.reference,
       date: item.date,
       number: $.number,
       description: $.description,
       received: item.received,
       created:item.created

   })
 
 )

修改Imtiyaz的答案

%dw 2.0
output application/json
---
{
    items: (payload.items ) flatMap ((item, index) ->  (
        item.lines map ((line) -> (item - 'lines' - "received" - "created ") ++ {
            description: line.description,
            number: line.number,
            created: item.created,
            received: item.received
        })
    ))
}

%dw 2.0
output application/json
---
item: payload.items flatMap ((item, index) ->

        (item.lines map {
       order: item.order,
       reference:item.reference,
       date: item.date,
       number: $.number,
       description: $.description,
       received: item.received,
       created:item.created

   })
 
 )

Modifying Imtiyaz's answer a bit

%dw 2.0
output application/json
---
{
    items: (payload.items ) flatMap ((item, index) ->  (
        item.lines map ((line) -> (item - 'lines' - "received" - "created ") ++ {
            description: line.description,
            number: line.number,
            created: item.created,
            received: item.received
        })
    ))
}

送舟行 2025-01-30 05:04:11

尝试以下脚本。

%dw 2.0
output application/json
---
{
    items: payload.items flatMap ((item, index) -> (
        item.lines map ((line) -> (item - 'lines') ++ {
            description: line.description
        })
    ))
}

try below script.

%dw 2.0
output application/json
---
{
    items: payload.items flatMap ((item, index) -> (
        item.lines map ((line) -> (item - 'lines') ++ {
            description: line.description
        })
    ))
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文