0
votes

Order_Entry_Date field format will be 6 digits. "120xxx" > "120" = year 2020 and "xxx" is the number of days into that year. Example: 121001 = 1 Jan 2021

Record_Timestamp field in this Input format - "YYYY-MM-DD-HH.mm.ss.decimalsecond" to output format "DD MMM YYYY - HH:mm:ss" (omit decimal seconds)

Input

{
 "orders": [
  {
    
   "Order_Number": "1112999",  
   "Order_Entry_Date": "120042",
   "Record_Timestamp": "2020-08-09-21.10.21.350090"
  }
 ]
}

Output

{
 "orders": [
  {
    
   "Order_Number": "1112999",  
   "Order_Entry_Date": "13 Mar 2020", 
   "Record_Timestamp":  "09 Aug 2020 21:10:21"
  }  
 ]
}
2

2 Answers

1
votes

Looks like that's a Julian type date for the Order_Entry_Date field.
The following script should work to produce the expected output.

%dw 2.0
output application/json
fun convertJulianDate(d) = do {
    var day = d[3 to 5]
    var year = d[1 to 2]
    ---
    ((("0101" ++ year ) as Date {format: "ddMMyy"}) + ("P$(day - 1)D" as Period)) as Date {format: "dd MMM yyyy"}
} 
---
{
    orders: payload.orders map {
        "Order_Number": $.Order_Number,  
        "Order_Entry_Date": convertJulianDate($.Order_Entry_Date),
        "Record_Timestamp": $.Record_Timestamp as LocalDateTime {format: "yyyy-MM-dd-HH.mm.ss.SSSSSS"} as String {format: "dd MMM yyyy HH:mm:ss"}
    }
}
0
votes

Try this:

%dw 2.0
output application/json
var data = {
 "orders": [
  {
    
   "Order_Number": "1112999",  
   "Order_Entry_Date": "120042",
   "Record_Timestamp": "2020-08-09-21.10.21.350090"
  }
 ]
}
---
data.orders map {
    Order_Number: $.Order_Number,
    Order_Entry_Date: $.Order_Entry_Date,
    Record_TimeStamp: $.Record_Timestamp[0 to 18] 
                        as LocalDateTime {format: "yyyy-MM-dd-HH.mm.ss"}
                        as String {format: "dd MMM yyyy HH:mm:ss"}
}

I have no clue what kind of date you have in Order_Entry_Date so I let it be.

I also made assumptions about the timestamp format. If you provide the range of values I may be able to revise.