Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Renaming Special character key with Jolt transform

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[
  {
    "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"
} ]

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading