Simplifying Google Sheet JSON using Jolt - jolt

I have gone through most of the test cases in Jolt that seem to serve as examples, but cannot find anything that does what I am looking for. For background, the source code is a stripped version of what comes from a google sheet. So rows and columns.
Source JSON:
[
{
"values": [
{
"formattedValue": "ACHME - Thailand"
},
{
"formattedValue": "5,368.11"
},
{
"formattedValue": "17.09%"
}
]
},
{
"values": [
{
"formattedValue": "ACHME-B2A"
},
{
"formattedValue": "101.47"
},
{
"formattedValue": "0.32%"
}
]
},
{
"values": [
{
"formattedValue": "ACHME-B2E"
},
{
"formattedValue": "83.79"
},
{
"formattedValue": "0.27%"
}
]
}
]
Desired Output:
[
{
"row": [
"ACHME - Thailand",
"5,368.11",
"17.09%"
]
},
{
"row": [
"ACHME-B2A",
"101.47",
"0.32%"
]
},
{
"row": [
"ACHME-B2E",
"83.79"
"0.27%"
]
}
]
I have tried this Jolt that gets me most of the way there, but I am still losing the row boundaries. It all comes out with one 'row' element and all of the values in an array.
[
{
"operation": "shift",
"spec": {
"*": {
"values": {
"*": {
"formattedValue": "row[]"
}
}
}
}
}
]

Spec
[
{
"operation": "shift",
"spec": {
"*": { // row index
"values": {
"*": { // column index
"formattedValue": "[&3].row[&1]"
}
}
}
}
}
]
Note, this assumes that all the incoming "values" arrays are the same length.

Related

JOLT Transformation with Arrays

Looking for help on Jolt transformation below
{
"consents": [
{
"consent-data": [
{
"consent-key": "DOB",
"consent-value": "02/2006"
}
],
"consent-id": "123",
"consent-indicator": "true",
"consent-type": "COPPA",
"resource-id": "456"
},
{
"consent-data": [
{
"consent-key": "DOB",
"consent-value": "02/2006"
}
],
"consent-id": "567",
"consent-indicator": "true",
"consent-type": "COPPA",
"resource-id": "678"
}
]
}
Expected Output :
{
"Consents": [
{
"consentDataResponse": [
{
"consentKey": "DOB",
"consentValue": "02/2006"
}
],
"consentId": "123",
"consentIndicator": "true",
"consentType": "COPPA",
"resourceId": "456"
},
{
"consentDataResponse": [
{
"consentKey": "DOB",
"consentValue": "02/2006"
}
],
"consentId": "567",
"consentIndicator": "true",
"consentType": "COPPA",
"resourceId": "678"
}
]
}
Trasformation iam using :
[
{
"operation": "shift",
"spec": {
"consents": {
"*": {
"consent-id": "consents[&1].retailerId",
"consent-indicator": "consents[&1].consentIndicator",
"consent-type": "consents[&1].consentType",
"resource-id": "consents[&1].resoureId",
"consent-data": {
// loop thru the orderItems array
"*": {
"consent-key": "consentDataResponse[&1].consentKey",
"consent-value": "consentDataResponse[&1].consentValue"
}
}
}
}
}
}
]
Current output :
{
"consentDataResponse" : [ {
"consentKey" : [ "DOB", "DOB1" ],
"consentValue" : [ "02/2006", "03/2006" ]
} ],
"consents" : [ {
"consentIndicator" : "true",
"consentType" : "COPPA",
"resoureId" : "22=",
"retailerId" : "11="
}, {
"consentIndicator" : "false",
"consentType" : "COPPA1",
"resoureId" : "44=",
"retailerId" : "33="
} ]
}
Note - Here, consents and consentDataResponse will be repeated, currently I am getting consentDataResponse as a separate object with consolidated values but it should be per consents. Could you please help me here
[
{
"operation": "shift",
"spec": {
"consents": {
"*": {
"consent-data": {
"*": {
"consent-key": "Consents[&3].consentDataResponse[&1].consentKey",
"consent-value": "Consents[&3].consentDataResponse[&1].consentValue"
}
},
"consent-id": "Consents[&1].consentId",
"consent-indicator": "Consents[&1].consentIndicator",
"consent-type": "Consents[&1].consentType",
"resource-id": "Consents[&1].resourceId"
}
}
}
}
]
You did almost correct and just added indexing inside the consent-data loop.

Jolt Transformation to match on multiple key values

I'm struggling to find the correct jolt spec to evaluate the values of two keys prior to creating an output. Any ideas?
Input:
{
"ticketInformation": {
"area": "001",
"site": "ABC",
"ticketType": "TC"
}
}
Spec:
[
{
"operation": "shift",
"spec": {
"ticketInformation": {
"area": {
"001": {
"#Works": "OneMatch"
}
},
"ticketType": {
"TC": {
"#OnlyEvaluatingTicketType": "HowToEvalueValuesOfTwoKeys"
}
}
}
}
}
]
Output:
{
"OneMatch" : "Works",
"HowToEvalueValuesOfTwoKeys" : "OnlyEvaluatingTicketType"
}
The desired output is the same as the actual output but ONLY if area=001 AND troubleType=TC.
I guess this is the spec you are looking for
[
{
"operation": "shift",
"spec": {
"ticketInformation": {
"area": {
"001": {
"#(2,ticketType)": {
"TC": {
"#Yes": "BothMatching"
}
}
}
}
}
}
}
]

Jolt spec file multiple array of element

I am trying to write a jolt transformation for the input below:
Input
[{
"factValues": [
{
uniqeid:"1",
"values":"1234567"
},
{
uniqeid:"1",
"teams":"abcde"
}]
},{
"factValues": [
{
uniqeid:"2",
"values":"6758595"
},
{
uniqeid:"2",
"teams":"medrgeh"
}]
}
]
Excepted Output.
{
"factValues": [{
uniqeid:"1",
"values":'1234567',
"teams":'76599876'
},
{
uniqeid:"2",
"values":'6758595',
"teams":'medrgeh'
}
]
}
Kindly help me to achieve the expected output.json in spec.json. The spec is not transforming as expected output. I want learn how to use attributes inside the string parser
Shifted all the values to the factValues. Then selected the first element from the uniqueid array,
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": {
"uniqeid": "factValues.[&3].uniqeid",
"values": "factValues.[&3].values",
"teams": "factValues.[&3].teams"
}
}
}
}
}, {
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": {
"uniqeid": "=firstElement(#(1,uniqeid))"
}
}
}
}
]

How will the JOLT spec look to achieve desired result with the following input?

I am having troubles transforming JSON payload into the desired document.
I have following input:
{
"events": [
{
"recipientId": "r0001"
},
{
"recipientId": "r0002"
}
],
"networkResponseTime": 1234
}
Desired output:
{
"events": [
{
"recipientIds": "r0001",
"networkResponseTime": 1234"
},
{
"recipientIds": "r0002",
"networkResponseTime": 1234"
}
]
}
How will the JOLT spec look like for this example?
So far I have smth like this:
[{
"operation": "shift",
"spec": {
"events": {
"*": {
"recipientId": "events[&1].recipientIds"
}
}
}
}]
Spec
[{
"operation": "shift",
"spec": {
"events": {
"*": {
"recipientId": "events[&1].recipientIds",
//
// go back up to the root of the tree, and then
// come back down the key "networkResponseTime", and
// send it's value to "events[&1].networkResponseTime"
"#(2,networkResponseTime)": "events[&1].networkResponseTime"
}
}
}
}]

Json array transformation using jolt

i want to transform a JSON array,
JSON:
{
"data1": {
"data2": [
{
"element1": "value1",
"entity": [
"array0",
{
"element2": [
"abc",
"pqr",
"xyz"
]
}
]
}
desired output:
"data2" : {
"element1":"value1",
"entity" : "array0",
"element2":[abc,pqr,xyz]
}
Please find find way to transform this JSON
i have tried with different approach to access the element1 . its not working
Spec
[
{
"operation": "shift",
"spec": {
"data1": {
"data2": {
"*": { // data2 array index
"element1": "data2[&1].element1",
"entity": {
// index input entity array explicilty with "0" and "1"
"0": "data2[&2].entity",
"1": {
"element2": "data2[&3].element2"
}
}
}
}
}
}
}
]