Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to concatenate the values of JSON attributes using JOLT?

I am wondering if there is any way to concatenate the values of JSON attributes into one new attribute using JOLT transformation.

For example, I have the following JSON:

{
  "name": "Mary",
  "Year Joined": "2017",
  "Gender": "Female"
}

and I would like it to be transformed into this:

{
  "new": "Mary_2017_Female"
}

Is it possible to do this using JOLT or are there other alternative ways to do it?

like image 987
purplewind Avatar asked Jan 19 '17 03:01

purplewind


2 Answers

Yes, but it uses a "beta" transform that may change in the future.

http://jolt-demo.appspot.com/#modify-stringConcat

like image 100
Milo S Avatar answered Nov 02 '22 03:11

Milo S


Expanding @Milo answer (not a fan of links outside SO)

Yes, you can achieve this using modify-overwrite-beta transform

The specification for your example would look like:

[
  {
     "operation": "modify-overwrite-beta",
    "spec": {
       "new": "=concat(@(1,name),'_',@(1,Year Joined),'_',@(1,Gender))"
    }
  }
]
like image 40
mido Avatar answered Nov 02 '22 03:11

mido