简体   繁体   中英

Using Jolt for json transformation :

I'm expecting the format of Input and output json will be same with one field modification ie name to firstname. Further leads would be appreciated. Thanks in Advance

Input Json:

[
  {
    "id": 123,
    "name": "Pankaj Kumar",
    "permanent": true,
    "address": {
      "street": "El Camino Real",
      "city": "San Jose",
      "zipcode": 95014
    },
    "phoneNumbers": [
      9988664422,
      1234567890
    ],
    "role": "Developer"
  },
  {
    "id": 124,
    "name": "Rahul Dravid",
    "permanent": false,
    "address": {
      "street": "Baner",
      "city": "Pune",
      "zipcode": 95014
    },
    "phoneNumbers": [
      9988664422,
      1234567890
    ],
    "role": "Product owner"
  }
]

Spec json:

[
  {
    "operation": "default",
    "spec": {
      "*": {
        "id": "id",
        "name": "firstname",
        "permanent": "permanent",
        "address": "Employee address",
        "phoneNumbers": "phoneNumbers",
        "role": "role",
        "fname": "fname"
      }
    }
    }
]

Output json:

[ {
  "id" : 123,
  "name" : "Pankaj Kumar",
  "permanent" : true,
  "address" : {
    "street" : "El Camino Real",
    "city" : "San Jose",
    "zipcode" : 95014
  },
  "phoneNumbers" : [ 9988664422, 1234567890 ],
  "role" : "Developer",
  "fname" : "fname"
}, {
  "id" : 124,
  "name" : "Rahul Dravid",
  "permanent" : false,
  "address" : {
    "street" : "Baner",
    "city" : "Pune",
    "zipcode" : 95014
  },
  "phoneNumbers" : [ 9988664422, 1234567890 ],
  "role" : "Product owner",
  "fname" : "fname"
} ]

Expected OUTPUT JSon:

[ {
  "id" : 123,
  "firstname" : "Pankaj Kumar",
  "permanent" : true,
  "address" : {
    "street" : "El Camino Real",
    "city" : "San Jose",
    "zipcode" : 95014
  },
  "phoneNumbers" : [ 9988664422, 1234567890 ],
  "role" : "Developer",
  "fname" : "fname"
}, {
  "id" : 124,
  "name" : "Rahul Dravid",
  "permanent" : false,
  "address" : {
    "street" : "Baner",
    "city" : "Pune",
    "zipcode" : 95014
  },
  "phoneNumbers" : [ 9988664422, 1234567890 ],
  "role" : "Product owner",
  "fname" : "fname"
} ]

Use shift operation, to change the name to firstname

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "id": "[&1].id",
        "name": "[&1].firstname",
        "permanent": "[&1].permanent",
        "address": "[&1].address",
        "phoneNumbers": "[&1].phoneNumbers",
        "role": "[&1].role",
        "#fname": "[&1].fname"
      }
    }
  }
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM