简体   繁体   中英

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.

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

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

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.

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