Jolt: Concat of different postions

55 Views Asked by At

Input:

[
  {
    "policy": "Name",
    "PAFrstNm": "John"
  },
  {
    "PALastNm": "Jammy",
    "policy": "Name"
  },
  {
    "PAMiNm": "T",
    "policy": "Name"
  },
  {
    "policy": "Name",
    "PPFrstNm": "sam"
  },
  {
    "policy": "Name",
    "PPLastNm": "jim"
  },
  {
    "policy": "Name",
    "PPMiNm": "E"
  },
  {
    "policy": "Name",
    "PPFrstNm1": "jun"
  },
  {
    "policy": "Other",
    "Summer": "533A"
  },
  {
    "policy": "Other",
    "Winter": "588A"
  },
  {
    "PPLastNm1": "san",
    "policy": "Name"
  },
  {
    "PPMiNm1": "e",
    "policy": "Name"
  }
]

last time we tried:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*LastN*|*FrstN*|*MiN*": "@1,policy.&(0,1)fullna&(0,2)",
        "*er": "@1,policy.SWfullname"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "0|2|1": "&2.&1.[#1]"
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "*": "=join(' ',@(1,&))"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "@": "&2_&1.&",
          "$1": "&2_&1.policy"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "[]"
    }
  }
]

Current output of this jolt:

[
  {
    "PAfullnam": "John T Jammy",
    "policy": "Name"
  },
  {
    "PPfullnam": "sam E jim",
    "policy": "Name"
  },
  {
    "PPfullnam1": "jun e san",
    "policy": "Name"
  },
  {
    "SWfullname": "533A 588A",
    "policy": "Other"
  }
]

Expected one:

[
  {
    "PAfullnam": "John T Jammy", //here no change
    "policy": "Name"
  },
  {
    "PPfullnam": "jim E sam",   //PPLastNm+PPMiNm+PPFrstNm 
    "policy": "Name"
  },
  {
    "PPfullnam1": "san e jun ", //PPLastNm1+PPMiNm1+PPLastNm1
    "policy": "Name"
  },
  {
    "SWfullname": "533A 588A",  // no change
    "policy": "Other"
  }
]
1

There are 1 best solutions below

0
Barbaros Özhan On BEST ANSWER

All you should do is reorder the elements of the array as 1|2|0 instead of 0|2|1 for the PP prefixed arrays.

So, replace the second spec with the following one :

  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "0|2|1": "&2.&1[#1]"
        },
        "PP*": {
          "1|2|0": "&2.&1[#1]"
        }
      }
    }
  }