Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use shift and modify-overwrite-beta in jolt

I want to know how to use shift and modify-overwrite-beta for the below input. Please explain how it works with your answer.

my input

[
  {
    "data": {
      "firstName": "Leanne",
      "lastName": "Graham",
      "id": 111
    }
  },
  {
    "data": {
      "firstName": "Ervin",
      "lastName": "Howell",
      "id": 222
    }
  }
]

I want this output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
  "111": {
    "fullName": "Leanne Graham"
  },
  "222": {
    "fullName": "Ervin Howell"
  }
}

>Solution :

You can solve that in different ways.

1. This spec is more understandable:

  1. Order your list with the id value as a key in the shift operation: @(1,id)
  2. Concat firstName and lastName in the modify-overwrite-beta operation: =concat(@(1,firstName),' ',@(1,lastName))
  3. Remove unused keys in the remove operation: id, firstName, lastName
[
  {
    "operation": "shift",
    "spec": {
      "*": { // index of the array: 1, 2
        "*": { // data object
          "*": "@(1,id).&" // value of id in the current object: 111, 222
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": { // ids: 111, 222
        "fullName": "=concat(@(1,firstName),' ',@(1,lastName))"
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "*": { // ids: 111, 222
        "id": "",
        "firstName": "",
        "lastName": ""
      }
    }
  }
]

2. This spec is shorter:

  1. Concat firstName and lastName in the modify-overwrite-beta operation: =concat(@(1,firstName),' ',@(1,lastName))
  2. Get the value of id as a key and put fullname in it: key @(1,id).fullName, value @(0,fullName)
[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "*": {
          "fullName": "=concat(@(1,firstName),' ',@(1,lastName))"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "@(0,fullName)": "@(1,id).fullName"
        }
      }
    }
  }
]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading