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

Jolt: Conditional placing value if boolean is true

I have this case where if defaultshipping is true, the phone should be placed into shippingAddressBook->phone (same for billing). My transformation is close but the issue is that it is not grabbing the value of "phone".

Can someone help me with this please 🙂

Input:

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

{
  "phone": "869-947-4444",
  "defaultshipping": false,
  "defaultbilling": true
}

Expected Output:

{
  "billingAddressBook" : {
    "phone" : "869-947-4444"
  }
}

My transformation attempt:

[
  {
    "operation": "shift",
    "spec": {
      "defaultbilling": {
        "true": {
          "#phone": "billingAddressBook.phone"
        }
      },
      "defaultshipping": {
        "true": {
          "#phone": "shippingAddressBook.phone"
        }
      }
    }
  }
]

>Solution :

Yes, you’re so close, just need to go 2 level up in order to reach the level of phone and grab the value through use of @(2,phone) such as

[
  {
    "operation": "shift",
    "spec": {
      "defaultbilling": {
        "true": {
          "@(2,phone)": "billingAddressBook.phone"
        }
      },
      "defaultshipping": {
        "true": {
          "@(2,phone)": "shippingAddressBook.phone"
        }
      }
    }
  }
]
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