0
votes

I want to transform a JSON using JOLT like this:

Input: {
    "array": [
       "1","2","3","4"
    ],
    "array2": [
       {  
          "something": "123",
          "something1": "Plane"
       },
       {
          "something3": "567",
          "something4": "Car"
       }
    ]
}

Into the following format, as you can see from output I need data from both arrays to fit exact param names, not empty one like in the first or existed param names like in the second one.

Output: {
    "one_array": [
      {
       "code": "1", 
       "description": "", 
      },
      {
       "code": "2", 
       "description": "", 
      },
      {
       "code": "3", 
       "description": "", 
      },
      {
       "code": "4", 
       "description": "", 
      }
], "other_array": [
      {
          "id": "123",
          "type": "Plane"
      }, 
      {
          "id": "567",
          "type": "Car"
      }
]
}

Some clarifications are really appreciated

1

1 Answers

0
votes

You can achieve this using 2 shift operations and the default operation as below.

[
  {
    "operation": "shift",
    "spec": {
      "array": {
        "*": {
          "@": "one_array[&].id"
        }
      },
      "array2": {
        "*": {
          "*": {
            "@": "tmp_array[&2]"
          }
        }
      }
    }
   },
  {
    "operation": "shift",
    "spec": {
      "one_array": "one_array",
      "tmp_array": {
        "*": {
          "0": "other_array[&1].id",
          "1": "other_array[&1].type"
        }
      }
    }
   },
  {
    "operation": "default",
    "spec": {
      "one_array[]": {
        "*": {
          "description": ""
        }
      }
    }
   }
]