Can't figure out concatenation error in JOLT

38 Views Asked by At

I'm trying to concat text within jolt and as I'm going through I'm running into an error that I haven't really seen before. I am testing the code within the jolt transform demo if that helps.

Text I'm transforming:

{
  "jolt_PanelType": "SUPPLEMENT_FACTS",
  "ingredientDecks": [
    {
      "deckId": 32147818,
      "deckName": "Proprietary Blend",
      "deckType": "BLENDS",
      "operator": "=",
      "amount": 6,
      "uom": "g",
      "rawText": "of Dark Honey",
      "ingredientComposition": [],
      "productId": null,
      "columnIndex": 1,
      "formatBasedParsings": []
    }
  ]
}

Jolt I'm using to concat:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "jolt_PanelType": {
        "SUPPLEMENT_FACTS": {
          "@(2,ingredientDecks)": {
            "*": {
              "deckType": {
                "BLENDS": {
                  "@(2,rawText)": "=concat(@(1,deckName),' ',@(1,rawText))"
                }
              }
            }
          }
        }
      }
    }
  }
]

The error I'm receiving in the demo:

Error running the Transform.

JOLT Chainr encountered an exception constructing Transform className:com.bazaarvoice.jolt.Modifier.Overwritr at index:0.

OVERWRITR cannot have TransposePathElement RHS

Any help is appreciated! I'm really confused by the error cause looking at other examples it seems like people use concat with TransposePathElement on the RHS all the time so I don't know whats different about my case

1

There are 1 best solutions below

0
Barbaros Özhan On

Because the conditional can be used within the shift transformation, but not in the modify transformation. As a result, you might convert yours to this one :

[
  {
    "operation": "shift",
    "spec": {
      "jolt_PanelType": {
        "@": "&",
        "SUPPLEMENT_FACTS": {
          "@(2,ingredientDecks)": {
            "*": {
              "deckType": {
                "BLENDS": {
                  "@2,deckName": "ingredientDecks[0].newDeckName",
                  "@2,rawText": "ingredientDecks[0].newDeckName"
                }
              },
              "*": "ingredientDecks[0].&"
            }
          }
        }
      }
    }
  },
  { // 
    "operation": "modify-overwrite-beta",
    "spec": {
      "ingredientDecks": {
        "*": {
          "newDeckName": "=join(' ',@(1,&))"
        }
      }
    }
  }
]

the demo on the site https://jolt-demo.appspot.com/ is :

enter image description here