Skip to main content
SandyClouds
Gold ⭐️
April 14, 2023
Solved

help with Jolt tarnsformation

Hi All, 

Looking for some help with JOLT transformatio, which i am completely new.

my input JSON looks like this 

 

{
"type": "delete",
"timestamp": 1681484884000,
"binlog_filename": "bin.000003",
"binlog_position": 6378700,
"database": "db1",
"table_name": "records",
"table_id": 108,
"columns": [{
"id": 1,
"name": "id",
"column_type": 4,
"value": 259
}, {
"id": 2,
"name": "index_id",
"column_type": 4,
"value": 1
}, {
"id": 3,
"name": "state_id",
"column_type": 4,
"value": 1
}]
}

This is from mysql binlogs.

 

I want to transform it to have a single field..

 

[{
"id": 259
}]

 

from one of the tutorials here in cloudera comminity, i saw this JOLT transformation.

[
{
"operation": "shift",
"spec": {
"columns": {
"*": {
"@(value)": "[#1].@(1,name)"
}
}
}
}
]

 

But it gives all fileds.. but I just need one filed which is the ID. I need to drop rest all fields.. 

Can someone please help in this regards.

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
April 15, 2023

Hi,

If you are looking to set the id value for the first element in the columns array you can use the following spec:

 

[
{
"operation": "shift",
"spec": {
"columns": {
"0": {
"value": "[].@(1,name)"
}
}
}
}
]

 

If that helps please accept solution.

2 replies

SAMSAL
SAMSALAnswer
Platinum ⭐️⭐️⭐️
April 15, 2023

Hi,

If you are looking to set the id value for the first element in the columns array you can use the following spec:

 

[
{
"operation": "shift",
"spec": {
"columns": {
"0": {
"value": "[].@(1,name)"
}
}
}
}
]

 

If that helps please accept solution.

Translate
SandyClouds
Gold ⭐️
April 17, 2023

@SAMSAL Kudos to you.. it worked.. /\

Translate