skip to Main Content

I am trying to convert the below JSON payload into a JSON which has the field name as the value of the field:
The jolt file that I have is working if field values are different. But if field values are the same then it is giving an array in the response.

Can you please help to provide jolt specifications for this?

Input JSON Payload :

{
  "action": {
    "allowPartialSuccess": true,
    "records": [
      {
        "ZuoraSubscriptionExtId": "962041ad-e673-492a-a071-5e0ab74ea001",
        "CPQSubscriptionID__c": "5640029343"
      },
      {
        "ZuoraSubscriptionExtId": "962041ad-e673-492a-a071-5e0ab74ea001",
        "CPQSubscriptionID__c": "5640029343"
      }
    ],
    "type": "update"
  }
}

`

Expected output JSON Payload :

{
  "action" : {
    "allowPartialSuccess" : true,
    "records" :  {
      "962041ad-e673-492a-a071-5e0ab74ea001" : {
        "CPQSubscriptionID__c" : "5640029343"
      }
    }, {
      "962041ad-e673-492a-a071-5e0ab74ea001" : {
        "CPQSubscriptionID__c" : "5640029343"
      }
    } ,
    "type" : "update"
  }
}

JOLT specification that I am using :

[
  {
    "operation": "shift",
    "spec": {
      "action": {
        "allowPartialSuccess": "action.allowPartialSuccess",
        "records": {
          "*": {
            "CPQSubscriptionID__c": "action.records.@(1,ZuoraSubscriptionExtId).CPQSubscriptionID__c"
          }
        },
        "type": "action.type"
      }
    }
  }
]

2

Answers


  1. Your expected output is wrong in the question.

    If you want an object in your record, You can use this spec:

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "&": "&1.&",
            "records": {
              "*": {
                "CPQSubscriptionID__c": "&3.&2.@(1,ZuoraSubscriptionExtId).CPQSubscriptionID__c"
              }
            }
          }
        }
      },
      {
        "operation": "cardinality",
        "spec": {
          "*": {
            "records": {
              "*": {
                "*": "ONE"
              }
            }
          }
        }
      }
    ]
    
    

    And if you want an array in your output. You can use this spec:

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "*": "&1.&",
            "records": {
              "*": {
                "CPQSubscriptionID__c": "&3.&2[].@(1,ZuoraSubscriptionExtId).CPQSubscriptionID__c"
              }
            }
          }
        }
      }
    ]
    
    
    Login or Signup to reply.
  2. You can use this shift transformation spec

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "*": "&1.&", // &1 replicates the literal "action"
            "records": {
              "*": {
                "C*": "&3.&2.@(1,ZuoraSubscriptionExtId).&" // &3 replicates the literal "action" (by going three level up the tree), &2 for "records", & replicates the current level attribute
              }
            }
          }
        }
      }
    ]
    

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

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search