Home > Net >  Rename fields in JOLT transformation
Rename fields in JOLT transformation

Time:02-05

I want to change the name of fields in an array by Jolt. Please explain how it works with your answer.

Input:

{
    "referenceName": "***",
    "name": "***"
}

Desired output:

{
    "ReferenceName": "***",
    "ColumnName": "***"
}

CodePudding user response:

You can use this simple spec:

[
  {
    "operation": "shift",
    "spec": {
      "referenceName": "ReferenceName",
      "name": "ColumnName"
    }
  }
]

Or you can have simpler:

[
  {
    "operation": "shift",
    "spec": {
      "r*": "R&(0,1)",
      "n*": "ColumnN&(0,1)"
    }
  }
]

When you want to change some names in your JSON, You can use the shift operation like the above spec:

  1. r*: match all keys that started with the r like referenceName and * match everything after r that equals eferenceName. You can write R&(0,1) that &(0,1) value is equal to first *.
  2. n*: match all keys that started with the n like name and * match everything after n that is equal to ame. You can write ColumnN&(0,1) that &(0,1) value is equal to first *.

Note: & means the key's value, But when you use the &(0,1), you are saying that in the 0 level or current level please get the first * value. Suppose you had a second * in this level, You should get it like this: &(0,2)

  • Related