Support Questions

Find answers, ask questions, and share your expertise

Can JOLT be used to decompose the value of the date time field in the following JSON

The JSON I have looks like this:

{     
"year":2018,   
"type":"N",  
"issued":"2018-10-17T20:16:00.000Z",   
"affectedFIR":"ZOA",   
"minimumFL":"000"
}

I'd like to figure out how to extract the value of issued, and decompose it into a JSON that looks like the following

{ 
"issued_year":"2018", 
"issued_month":"10", 
"issued_day":"17", 
"issued_hour":"20", 
"issued_minute":"16",
"issued_second":"00"
}
1 ACCEPTED SOLUTION

Explorer

@David Sargrad,

JOLT cannot do that for you. You need to first get the value of the issued field in a flowfile attribute(using EvaluateJsonPath), then you can use expression language functions on that attribute to extract the year, month, date and so on from that attribute. You can use expression language in JOLT.

[
	{
		"operation": "default",
		"spec": {
			"issued_year": "${date_attribute:toNumber():format('YYYY')}",
			"issued_month": "${date_attribute:toNumber():format('MM')}"
		}
	}
]

Assuming that date_attribute is the attribute containing the evaluated date.

View solution in original post

2 REPLIES 2

Explorer

@David Sargrad,

JOLT cannot do that for you. You need to first get the value of the issued field in a flowfile attribute(using EvaluateJsonPath), then you can use expression language functions on that attribute to extract the year, month, date and so on from that attribute. You can use expression language in JOLT.

[
	{
		"operation": "default",
		"spec": {
			"issued_year": "${date_attribute:toNumber():format('YYYY')}",
			"issued_month": "${date_attribute:toNumber():format('MM')}"
		}
	}
]

Assuming that date_attribute is the attribute containing the evaluated date.

New Contributor

This can be done by jolt like this:


[
{
"operation": "modify-overwrite-beta",
"spec": {
"issued_year": "=substring(@(1,issued),0,4)",
"issued_month": "=substring(@(1,issued),5,7)",
"issued_day": "=substring(@(1,issued),8,10)",
"issued_hour": "=substring(@(1,issued),11,13)",
"issued_minute": "=substring(@(1,issued),14,16)",
"issued_second": "=substring(@(1,issued),17,19)"
}
},
{
"operation": "shift",
"spec": {
"issued_year": "issued_year",
"issued_month": "issued_month",
"issued_day": "issued_day",
"issued_hour": "issued_hour",
"issued_minute": "issued_minute",
"issued_second": "issued_second"
}
}
]

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.