I'm new with Jolt and I need to have two field having different name but same value coming from the input JSON.
INPUT:
{
"date": 15746555589,
"sensorid": "23r098hd20c8jd02hd0h02300000000000"
}
DESIDERED OUTPUT:
{
"lastseen": 15746555589,
"firstseen": 15746555589,
"sensorid": "23r098hd20c8jd02hd0h02300000000000"
}
This spec should work:
[
{
"operation": "shift",
"spec": {
"date": "lastseen",
"#(1,date)": "firstseen",
"*": "&"
}
}
]
Related
how to convert the following data
{
"name" : "abcd",
"middleName" : "srivastav"
}
into
{
"name" : "abcd",
"middleName" : "srivastav"
"id" : "abcd"
}
by using a jolt transform such that the id and the name are within the same object as the expected output.
modify-default-beta or default operations will work for this :
[
{
"operation": "modify-default-beta",
"spec": {
"id": "abcd"
}
}
]
One option is to replicate the value of name through use of "#(0,name)": while keeping the current attributes by "*": "&" notation within a shift transformation such as
[
{
"operation": "shift",
"spec": {
"*": "&",
"#(0,name)": "id"
}
}
]
the demo on the site http://jolt-demo.appspot.com/ is
or another option is to use a modify(overwrite/default) transformation to dynamically replicate the value of name attribute for id such as
[
{
"operation": "modify-overwrite-beta",
"spec": {
"id": "#(1,name)"
}
}
]
the second demo is
Am new to nifi(1.14) and using JOLTTransform processor to transfer the input json (flatten) to nested json. I could not able to fix with the JOLT Schema. kindly help me on this.
The input JSON is :
[
{
"executionTime": "2244",
"processorId": "3ef03f9c-b42c-4c4e-9d5f-d14878bb2c84",
"filename": "Trading",
"processStartTime": "2021-07-26 16:31:19",
"processSQL": "TradingDetails.sql",
"executionFetchTime": "2049",
"sourceCountValue": "5076",
"startTime": "1627297279651",
"processGroupName": "Trading"
},
{
"ProcessEndTime": "2021-07-26 16:31:29",
"completedTime": "1627297289412",
"processDuration": "0",
"destCountValue": "5076",
"tableName": "TRADINGDETAILS"
},
{
"ProcessEndTime": "2021-07-26 16:31:29",
"completedTime": "1627297289412",
"processDuration": "0",
"destCountValue": "5076",
"tableName": "CUSTTRADINGDETAILS"
}
]
and the expected JSON output is
{
"Trading": {
"Source": {
"executionTime": "2244",
"processorId": "3ef03f9c-b42c-4c4e-9d5f-d14878bb2c84",
"filename": "Trading",
"processStartTime": "2021-07-26 16:31:19",
"processSQL": "TradingDetails.sql",
"executionFetchTime": "2049",
"sourceCountValue": "5076",
"startTime": "1627297279651",
"processGroupName": "Trading"
},
"Destination": {
"TRADINGDETAILS": {
"ProcessEndTime": "2021-07-26 16:31:29",
"completedTime": "1627297289412",
"processDuration": "10",
"destCountValue": "5076",
"tableName": "TRADINGDETAILS"
},
"CUSTTRADINGDETAILS": {
"ProcessEndTime": "2021-07-26 16:31:29",
"completedTime": "1627297289412",
"processDuration": "10",
"destCountValue": "5076",
"tableName": "CUSTTRADINGDETAILS"
}
}
}
}
Thanks in Advance.
You can use successive shift transformations; enumarate the keys of the objects within the first one, and then rename them while nesting each under the related keys such as
[
{
"operation": "shift",
"spec": {
"*": "&"
}
},
{
"operation": "shift",
"spec": {
"0": "Trading.Source",
"*": "Trading.Destination.#(0,tableName)"
}
}
]
I am having an array of objects in the given format:
[
{
"meta": [
{
"id": "101A"
},
{
"id": "101B"
}
]
}
]
Can someone help me with jolt spec I want the final output in the following format:
[
{
"meta": [
"101A",
"101B",
......
]
}
]
Thanks in advance!
Basically you want to iterate over your two arrays using the "*", and when iterating over your second array (meta) just get the id attribute and send to the meta array (ignore the object). See if this helps you understand:
[
{
"operation": "shift",
"spec": {
"*": {
"meta": {
"*": {
"id": "meta"
}
}
}
}
}
]
I need to transform a JSON response from one time-series DB and output it to as a response in a new format.
Having an input JSON array, I need to transform it with JoltTransformJson (NiFi) and add a key-value for each item from a FlowFile attribute.
This is my input JSON:
{
"Items": [
{
"Timestamp": "2020-04-29T07:46:20.558731Z",
"Value": 66.0303
},
{
"Timestamp": "2020-04-29T07:46:35.558731Z",
"Value": 69.11584
}
]
}
The desired output should be:
[{
"sensor_id": "xyz",
"sample_time": "2020-04-29T07:46:20.558731Z",
"sample_value": 66.0303
}, {
"sensor_id": "xyz",
"sample_time": "2020-04-29T07:46:35.558731Z",
"sample_value": 69.11584
}]
where sensor_id is a FlowFile attribute...
I came across to this spec:
[{
"operation": "shift",
"spec": {
"Items": {
"*": {
"#Timestamp": "[#2].sample_time",
"#Value": "[#2].sample_value",
"${sensor_id}": "[#2].sensor_id"
}
}
}
}]
But I cannot get the sensor_id in the output json.... instead, this is what I get:
[{
"sample_time": "2020-04-29T07:46:20.558731Z",
"sample_value": 66.0303
}, {
"sample_time": "2020-04-29T07:46:35.558731Z",
"sample_value": 69.11584
}]
Finally I've managed to project the ${sensor_id} into the output json, what was missing is #, so the final spec will be:
[{
"operation": "shift",
"spec": {
"Items": {
"*": {
"#Timestamp": "[#2].sample_time",
"#Value": "[#2].sample_value",
"#${sensor_id}": "[#2].sensor_id"
}
}
}
}]
Now, I've found that the Timestamp returned from my time-series DB is not exact what I need it to be. Instead I would like to convert it to integer timestamp (epoch sinse 1970)... Any idea how this can be achieved?
I have Json array with each of its object having dynamic attributes. I have to merge all the object into one Json object in nifi with common attribute's value concatenated and other attributes as it is.
I have already tried following spec, and it is giving common attributes as array list. But I want that common attribute's value to be concatenated and I don't know how to do that. Any suggestion would be really helpful. Thanks in advance.
[
{
"operation": "shift",
"spec": {
"*": {
"*": "&"
}
}
}
]
The input is like( NOTE: The attributes are dynamic so not sure always going to have these attributes)
[
{
"firstName": "Sam1",
"lastName": "Achom1",
"place": "Silchar1"
},
{
"firstName": "Saya2",
"lastName": "Singh2",
"place": "Macherial2",
"Second1stAttribute": "SomeValue"
},
{
"firstName": "Sam3",
"lastName": "Achom3",
"place": "Silchar3",
"Third2ndAttribute": "SomeValue2"
}
]
The output I am getting with before mentioned spec
{
"firstName" : [ "Sam1", "Saya2", "Sam3" ],
"lastName" : [ "Achom1", "Singh2", "Achom3" ],
"place" : [ "Silchar1", "Macherial2", "Silchar3" ],
"Second1stAttribute" : "SomeValue",
"Third2ndAttribute" : "SomeValue2"
}
And Expecting the output as
{ "firstName" : "Sam1 Saya2 Sam3",
"lastName" : "Achom1 Singh2 Achom3",
"place" : "Silchar1 Mancherial2 Silchar3",
"Second1stAttribute" : "SomeValue",
"Third2ndAttribute" : "SomeValue2"
}
You can "join" the items from your arrays. This spec will do the trick:
[
{
"operation": "shift",
"spec": {
"*": {
"*": "&"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": "=join(' ',#(1,&))"
}
}
]