I have the input like below,
Input:
{
"a": 1,
"b": 2
}
Spec:
[
{
"operation": "shift",
"spec": {
"a": {
"#(2,b)": {
"#Matched": "result"
},
"*": {
"#Not Matched": "result"
}
}
}
}]
Output:
{
"result" : [ "Matched", "Not Matched" ]
}
Expected:
{
"result" : "Not Matched"
}
Can anyone please suggest me help to work it as usual.
You can transform it in three steps:
move values to keys
find matched key
add "Not match" result if matched key was not found
(can't imagine why it doesn't work with values)
Smth like:
[
{
"operation": "shift",
"spec": {
"*": "&.#0"
}
},
{
"operation": "shift",
"spec": {
"a": {
"*": {
"#(2,b.&)": {
"#Matched": "result"
}
}
}
}
},
{
"operation": "default",
"spec": {
"result": "Not Matched"
}
}
]
Related
I am trying to convert the below JSON payload into a JSON which has the field name as the value of the field:
The jolt file that I have is working if field values are different. But if field values are the same then it is giving an array in the response.
Can you please help to provide jolt specifications for this?
Input JSON Payload :
{
"action": {
"allowPartialSuccess": true,
"records": [
{
"ZuoraSubscriptionExtId": "962041ad-e673-492a-a071-5e0ab74ea001",
"CPQSubscriptionID__c": "5640029343"
},
{
"ZuoraSubscriptionExtId": "962041ad-e673-492a-a071-5e0ab74ea001",
"CPQSubscriptionID__c": "5640029343"
}
],
"type": "update"
}
}
`
Expected output JSON Payload :
{
"action" : {
"allowPartialSuccess" : true,
"records" : {
"962041ad-e673-492a-a071-5e0ab74ea001" : {
"CPQSubscriptionID__c" : "5640029343"
}
}, {
"962041ad-e673-492a-a071-5e0ab74ea001" : {
"CPQSubscriptionID__c" : "5640029343"
}
} ,
"type" : "update"
}
}
JOLT specification that I am using :
[
{
"operation": "shift",
"spec": {
"action": {
"allowPartialSuccess": "action.allowPartialSuccess",
"records": {
"*": {
"CPQSubscriptionID__c": "action.records.#(1,ZuoraSubscriptionExtId).CPQSubscriptionID__c"
}
},
"type": "action.type"
}
}
}
]
You can use this shift transformation spec
[
{
"operation": "shift",
"spec": {
"*": {
"*": "&1.&", // &1 replicates the literal "action"
"records": {
"*": {
"C*": "&3.&2.#(1,ZuoraSubscriptionExtId).&" // &3 replicates the literal "action" (by going three level up the tree), &2 for "records", & replicates the current level attribute
}
}
}
}
}
]
the demo on the site http://jolt-demo.appspot.com/ is
Your expected output is wrong in the question.
If you want an object in your record, You can use this spec:
[
{
"operation": "shift",
"spec": {
"*": {
"&": "&1.&",
"records": {
"*": {
"CPQSubscriptionID__c": "&3.&2.#(1,ZuoraSubscriptionExtId).CPQSubscriptionID__c"
}
}
}
}
},
{
"operation": "cardinality",
"spec": {
"*": {
"records": {
"*": {
"*": "ONE"
}
}
}
}
}
]
And if you want an array in your output. You can use this spec:
[
{
"operation": "shift",
"spec": {
"*": {
"*": "&1.&",
"records": {
"*": {
"CPQSubscriptionID__c": "&3.&2[].#(1,ZuoraSubscriptionExtId).CPQSubscriptionID__c"
}
}
}
}
}
]
I am trying to convert the below JSON payload into a JSON that has the field name as the value of the field:
The jolt file that I have is working if field values are different. But if field values are the same then it is giving an array in the response.
Can you please help to provide jolt specifications for this?
Input JSON Payload:
{
"action": {
"Success": true,
"records": [
{
"Id": "Test_abc",
"SubscriptionID": "ID_1"
},
{
"Id": "Test_abc",
"SubscriptionID": "ID_2"
},
{
"Id": "Test_xyz",
"SubscriptionID": "ID_3"
}
],
"type": "update"
}
}
Expected output:
{
"action": {
"Success": true,
"records": {
"Test_abc": {
"SubscriptionID": "ID_1"
},
"Test_abc": {
"SubscriptionID": "ID_2"
},
"Test_xyz": {
"SubscriptionID": "ID_3"
}
},
"type": "update"
}
}
Solution not found yet.
You can use the following shift transformation spec
[
{
"operation": "shift",
"spec": {
"*": {
"*": "&1.&", // &1 replicates the literal "action"
"records": {
"*": {
"S*": "&3.&2.#(1,Id).&" // &3 replicates the literal "action" (by going three level up the tree), &2 for "records", & replicates the current level attribute
}
}
}
}
}
]
presumingly converting one of the Id value from Test_abc to another one such as Test_def, since the desired output is wrong as a JSON value(There cannot be more than one object with the same tag at the same level)
Your output is wrong. You can't have multiple objects with the same keys.
If You want to support all objects of records array, You should bring them into an array like this spec:
[
{
"operation": "shift",
"spec": {
"*": {
"*": "&1.&",
"records": {
"*": {
"S*ID": "&3.&2[].#(1,Id).&"
}
}
}
}
}
]
But, if you want to have an object as your records in the output, You should remove the duplicate ID like this spec:
[
{
"operation": "shift",
"spec": {
"*": {
"*": "&1.&",
"records": {
"*": {
"S*ID": "&3.&2.#(1,Id).&"
}
}
}
}
},
{
"operation": "cardinality",
"spec": {
"*": {
"records": {
"*": {
"*": "ONE"
}
}
}
}
}
]
I am trying to convert below json payload into a json payload which has field name as the value of the field:
Can you please help to provide jold specification for this ?
Input JSON Payload :
{
"action": {
"allowPartialSuccess": false,
"records": [
{
"recordid": "a4c6364e-4446-47d0-b014-c20ca014fdb3",
"ShipToCustomerTextualAddress__c": "TestAddress1",
"ResellerPO__c": "TestAddress1",
"InvoiceCDBID__c": "TestAddress1"
},
{
"recordid": "73781a94-9660-4f69-9bde-f2bf1991317d",
"ShipToCustomerTextualAddress__c": "TestAddress2",
"ResellerPO__c": "TestAddress2",
"InvoiceCDBID__c": "TestAddress2"
}
],
"type": "update"
}
}
Desired Output Payload :
{
"action": {
"allowPartialSuccess": false,
"records": {
"a4c6364e-4446-47d0-b014-c20ca014fdb3": {
"ShipToCustomerTextualAddress__c": "TestAddress1",
"ResellerPO__c": "TestAddress1",
"InvoiceCDBID__c": "TestAddress1"
},
"73781a94-9660-4f69-9bde-f2bf1991317d": {
"ShipToCustomerTextualAddress__c": "TestAddress2",
"ResellerPO__c": "TestAddress2",
"InvoiceCDBID__c": "TestAddress2"
}
},
"type": "update"
}
}
This will help you resolve it.
#(level,attribute) -->does the work.
[
{
"operation": "shift",
"spec": {
"action": {
"*": "action.&",
"records": {
"*": {
"ShipToCustomerTextualAddress__c": "action.records.#(1,recordid).&",
"ResellerPO__c": "action.records.#(1,recordid).&",
"InvoiceCDBID__c": "action.records.#(1,recordid).&"
}
}
}
}
}
]
You can think symbolically through use of ampersands to replicate the respective values within a shift transformation, and a remove transformation in order to get rid of the undesired attribute(recordid) at the end such as
[
{
"operation": "shift",
"spec": {
"*": {
"records": {
"*": "&2.&1.#(0,recordid)" // &2(going two levels up) stands for replicating "action", &1 is for "records"
},
"*": "&1.&" // which represents the "else" case(eg. all but the "records" object); &1 is for "action", and & is for "records"
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"*": {
"*": {
"recordid": ""
}
}
}
}
}
]
the demo on the site http://jolt-demo.appspot.com/ is
You would use this for solution this problem.
[
{
"operation": "shift",
"spec": {
"action": {
"*": "action.&",
"records": {
"*": "action.records.#recordid"
}
}
}
}
]
I have the following Jolt Spec
[
{
"operation": "shift",
"spec": {
"*": {
"value": "[]"
}
}
},
{
"operation": "shift",
"spec": {
"*": "values"
}
},
{
"operation": "default",
"spec": {
"values": []
}
}
]
For the following Input:
[
{
"value": 175
},
{
"value": 160
}
]
I get the expected result as following:
{
"values" : [ 175, 160 ]
}
And for the following Input:
[
{
"valueNum": 175
}
]
I again get an expected result as follows:
{
"values" : [ ]
}
But for the following input :
[
{
"value": 175
}
]
I get the following output
{
"values" : 175
}
I want to have the values in an array even if there is just one element in it like below:
{
"values" : [175]
}
Could you please help me fixing my Jolt Spec to get the desired result? Thanks!
Just using a single shift transformation spec as the following one would suffice
[
{
"operation": "shift",
"spec": {
"*": {
"*": "&s[]"
}
}
}
]
where & is a substitution for the key name(value), and s is a suffix to make the word plural
the demoes on the site http://jolt-demo.appspot.com/ are
Edit : If you need an output based on seperating the keys of the attributes to be value or the others(such as valueNum), then still a single spec like the one below would be sufficient :
[
{
"operation": "shift",
"spec": {
"*": {
"value": "&s[]",
"*": "&[]"
}
}
}
]
With the following spec, I was able to achieve all my use cases
[
{
"operation": "shift",
"spec": {
"*": {
"value": "[]"
}
}
},
{
"operation": "shift",
"spec": {
"*": "values[]"
}
},
{
"operation": "default",
"spec": {
"values": []
}
}
]
I need to map the headers and row values based on the dataKey value.
Input JSON
{
"headers": [
{
"dataKey": "col-0",
"displayName": "Product"
},
{
"dataKey": "col-1",
"displayName": "Dimension"
},
{
"dataKey": "col-2",
"displayName": "Output type "
}
],
"rows": [{
"col-0": "Medium ",
"col-1": "300x250",
"col-2": "HTML [Animate]"
}]
}
Expected Output
{
"Data" : {
"1" : {
"Product":"Medium",
"Dimension":"300x250",
"Output type":"HTML [Animate]"
}
}
}
Spec:
This is the JOLT Spec i am using currently it is not producing the expected ouptut
[
{
"operation": "shift",
"spec": {
"headers": {
"*": {
"displayName": {
"*": {
"#(2,dataKey)": {
"$": "Data.1.&",
"*": {
"#(6,rows.&)": "Data.1.&"
}
}
}
}
}
}
}
}
]
Please provide the jolt spec for above scanario. i tried but not able to get the expected result.
[
{
// segregate values of the same key and form respective arrays.
"operation": "shift",
"spec": {
"headers": {
"*": {
"displayName": "#(1,dataKey)"
}
},
"rows": {
"*": {
"*": "&"
}
}
}
},
{
// put every value array into temp array
"operation": "shift",
"spec": {
"*": "temp[]"
}
},
{
// map first index element as key and second index element as a value into the output
"operation": "shift",
"spec": {
"temp": {
"*": {
"1": "Data.1.#(1,[0])"
}
}
}
}
]