bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.54k stars 328 forks source link

Combine two values to an object #1149

Open LutzDev opened 2 years ago

LutzDev commented 2 years ago

Hello,

I am pretty new to Jolt. The source format was generated from some software and does not have a good structure, so I would like to transform this. Each text ("First text" and "Second text") has an associated link ("First text" -> "Link of first text"; "Second text" -> "Link of second text"). How would you do such a transformation? Any help please?

Sample Input:

{
  "flow": [
    "^First text",
    {
      "*": ".^.c-0"
    },
    "^Second text",
    {
      "*": ".^.c-1"
    },
    {
      "c-0": [
        {
          "->": "Link of first text"
        }
      ],
      "c-1": [
        {
          "->": "Link of second text"
        }
      ]
    }
  ]
}

Expected Output

{
  "flow": {
    "links": [
      {
        "message": "^First text",
        "link": "Link of first text"
       },
      {
        "message": "^Second text",
        "link": "Link of second text"
       }
     ]
  }
}