Home > Mobile >  Renaming Special character key with Jolt transform
Renaming Special character key with Jolt transform

Time:12-06

Please help me write the jolt spec to rename the key with a special character "@". When I place "@" in jolt spec, it is not working. I am getting the below error

Error running the Transform.

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

Invalid key:Company@1 can not have an @ other than at the front.

Please help in resolving this.

Input JSON

[
  {
    "C": "p",
    "ID": 1,
    "Company@1": "Tesla",
    "Age": 30.2,
    "Year": 1996,
    "Time": "22/10/1996"
  },
  {
    "C": "p",
    "ID": 2,
    "Company@1": "Facebook",
    "Age": 40.5,
    "Year": 2001,
    "Time": "22/10/2001"
  }
]

JOLT Spec

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "Company@1": "[#2].CompanyTest",
        "Age": "[#2].AgeTest",
        "*": "[#2].&"
      }
    }
  }
]

Expected Output

[ {
  "C" : "p",
  "ID" : 1,
  "CompanyTest" : "Tesla",
  "AgeTest" : 30.2,
  "Year" : 1996,
  "Time" : "22/10/1996"
}, {
  "C" : "p",
  "ID" : 2,
  "CompanyTest" : "Facebook",
  "AgeTest" : 40.5,
  "Year" : 2001,
  "Time" : "22/10/2001"
} ]

CodePudding user response:

Need to escape by prepending double backslash such as Company\\@1 in order to prevent getting an error

  • Related