Kiran HG
Kiran HG

Reputation: 39

JOLT Shift transformation

Need JOLT spec for JSON input and output.PFB the data for same.

Input :

{
  "customer": {
    "contact": {
      "name": {
        "firstName": "Karan",
        "lastName": "Singh",
        "middleName": null
      },
      "phone": "902-167-5435",
      "secondaryPhone": null,
      "email": "[email protected]"
    }
  }
}

Expected Output :

{
  "buyerInfo": {
    "id": "as123-e617-4410-969f",
    "primaryContact": {
      "name": {
        "firstName": "Karan",
        "lastName": "Singh"
      },
      "phone": {
        "completeNumber": "9021675435"
      },
      "email": {
        "emailAddress": "[email protected]"
      }
    }
  }
}

Please help me out on providing the JOLT spec for same. Also please share JOLT links.

Upvotes: 0

Views: 856

Answers (2)

Kiran HG
Kiran HG

Reputation: 39

[
  {
    "operation": "shift",
    "spec": {
      "customer": {
        "contact": {
          "name": {
            "firstName": "buyerInfo.primaryContact.name.firstName",
            "lastName": "buyerInfo.primaryContact.name.lastName"
          },
          "phone": "buyerInfo.primaryContact.phone.completeNumber",
          "email": "buyerInfo.primaryContact.email.emailAddress"
        }
      }
    }
  }
]

Got the JOLT Spec :)

Upvotes: 1

Barbaros Özhan
Barbaros Özhan

Reputation: 65323

Think symbolically, write less through use of some wildcards such as *, & and # as in the following spec

[
  {
    "operation": "shift",
    "spec": {
      "#as123-e617-4410-969f": "buyerInfo.id",
      "cu*": {
        "co*": {
          "name": {
            "*t*ame": "buyerInfo.primary&(2,0).&1.&"
          },
          "ph*": "buyerInfo.primarycontact.&.completeNumber",
          "em*": "buyerInfo.primarycontact.&.&Address"
        }
      }
    }
  }
]

The demo on the site http://jolt-demo.appspot.com/ is

enter image description here

Upvotes: 0

Related Questions