Skip to main content

Pivot Operation Use Cases

This guide explains the usage of the Pivot Operation, which allows transposing specific data in a JSON structure.

Parameters :

Get Key : We will provide the keyname which holds our array data.

Transposed Key Name : Name of key which need to be transposed as keyname.

Transposed Value : Name of key which need to be transposed as value.

Note: All the three variables are mandatory to pass.


Example Scenario :

Consider the following input data representing a dataset with various attributes.

{"bizdata_dataset":{
        "id":123,
        "name":"sample",
        "lastname":"dataset",
        "attributes":[
            {
                "attributename":"item",
                "attributevalue":"27",
                "attribute_code":12234
            },
            {
                "attributename":"item2",
                "attributevalue":"47",
                "attribute_code":12334
            },
            {
                "attributename":"item1",
                "attributevalue":"37",
                "attribute_code":13234
            }]}}

Pivot Operation Parameters:

Parameter : Get Key

attributes

Parameter : Transposed Key Name

"attributename"

Parameter : Transposed Value

"attributevalue"


Sample Output :

After applying the Pivot Operation, the input data will be transformed as follows:

{"bizdata_dataset":{
    "id": 123, 
    "name": "sample",
    "lastname": "dataset", 
    "attributes":[
        {
            "attributename": "item", 
            "attributevalue": "27", 
            "attribute_code": 12234
        },
        {
            "attributename": "item2",
            "attributevalue": "47",
            "attribute_code": 12334
        },
        {
            "attributename": "item1",
            "attributevalue": "37",
            "attribute_code": 13234
        }],
        "item": "27", 
        "item2": "47",
        "item1": "37"}}

Explanation of Output :

  • The original array of attributes remains unchanged.
  • The attributename values ("item", "item2", "item1") have been transposed to the root level of the bizdata_dataset object as keys.
  • The corresponding attributevalue values ("27", "47", "37") are now associated with the newly created keys ("item", "item2", "item1").