简体   繁体   English

从Dataweave 2.0中的JSON消息中提取最大/最早日期

[英]Extract Max/earliest date from JSON message in dataweave 2.0

My message structure: 我的讯息结构:

{
    "empid": "abc",
    "homeCountry": "IND",
    "dateOfBirth": "1969-01-01",
    "personalInformation": [
        {
            "salutation": "Mr",
            "firstName": "Ram",
            "lastName": "Naresh"
        }
    ],
    "EmpInfo": [
        {
            "hireDate": "2000-01-01",
            "LevDate": "2018-07-25",
            "jobInformation": [
                {
                    "isFullTimeEmployee": true,
                    "jobTitle": "Engineer",
                    "effectiveStartDate": "2018-01-05"
                },
                {
                    "isFullTimeEmployee": true,
                    "jobTitle": "Store Manager",
                    "effectiveStartDate": "2019-01-05"
                }
            ]
        }
    ]
}

I would like to extract the max date and index of the same so that i can declare it as var and use it in the mapping. 我想提取相同的最大日期和索引,以便可以将其声明为var并在映射中使用它。

Your question is not clear enough. 您的问题还不够清楚。 What date field do you want to use? 您要使用哪个日期字段? Here I created a solution that returns the index and the value of the jobInformation with the oldest effectiveStartDate 在这里,我创建了一个解决方案,该解决方案返回具有最旧的effectiveStartDate jobInformation的索引和值

payload.EmpInfo[0].jobInformation 
    map ((item, index) -> {value: item, index: index}) 
    maxBy ((item) -> item.value.effectiveStartDate as Date)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM