Reputation: 21
I am trying to transform input fields by matching pattern like "*|*|*"
where the words are separated by |
. However, I am not able to get it working. If I replace |
by :
, the spec works. Is there a special meaning to |
, how can use this as part of regular expressions?
Input :
{
"items": [
{
"itemId": "1234500AA",
"additionalData": "12345|20001|3000"
}
]
}
Spec :
[
{
"operation": "shift",
"spec": {
"items": {
"*": {
"itemId": "ID",
"additionalData": {
"*|*|*": {
"$(0,1)": ["cartMenuItems[&3].baseProductId", "cartMenuItems[&3].mdmId"],
"$(0,2)": "cartMenuItems[&3].code",
"$(0,3)": "cartMenuItems[&3].sku"
}
}
}
}
}
}
]
Output Expected :
{
"ID": "1234500AA",
"cartMenuItems": [
{
"baseProductId": "12345",
"mdmId": "12345",
"code": "20001",
"sku": "3000"
}
]
}
However, I get an error like below:
JOLT Chainr encountered an exception constructing Transform className:com.bazaarvoice.jolt.Shiftr at index:0.
Upvotes: 2
Views: 2039
Reputation: 1292
Jolt doesn't seem to like |
(as you would need to escape them), you could replace the |
:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"items": {
"*": {
"additionalDataTemp": "=split('\\|',@(1,additionalData))",
"additionalData": "=concat(@(1,additionalDataTemp[0]),'_',@(1,additionalDataTemp[1]),'_',@(1,additionalDataTemp[2]))"
}
}
}
},
{
"operation": "shift",
"spec": {
"items": {
"*": {
"itemId": "ID",
"additionalData": {
"*_*_*": {
"$(0,1)": ["cartMenuItems[&3].baseProductId", "cartMenuItems[&3].mdmId"],
"$(0,2)": "cartMenuItems[&3].code",
"$(0,3)": "cartMenuItems[&3].sku"
}
}
}
}
}
}
]
Or another way of doing it would be:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"items": {
"*": {
"additionalData": "=split('\\|', @(1,additionalData))",
"baseProductId": "@(1,additionalData[0])",
"mdmId": "@(1,additionalData[0])",
"code": "@(1,additionalData[1])",
"sku": "@(1,additionalData[2])"
}
}
}
},
{
"operation": "shift",
"spec": {
"items": {
"*": {
"itemId": "ID",
"*": "cartMenuItems[0].&"
}
}
}
},
{
"operation": "remove",
"spec": {
"cartMenuItems": {
"*": {
"additionalData": ""
}
}
}
}
]
Upvotes: 1