-1

Pls help with this jolt transformation.

Note:

  • If there is field "ServiceFamily" then change the field name to "tag1"

  • If there is field "PublisherName" then change the field name to "tag2"

Input:

[
  {
    "ServiceFamily": "Compute",
    "CostAllocationRuleName": null,
    "benefitId": null,
    "benefitName": null
  },
  {
    "PublisherName": "Microsoft",
    "ChargeType": "Usage",
    "Frequency": "UsageBased",
    "PricingModel": "OnDemand",
    "benefitName": null
  }
] 

Expected output:

[
  {
    "Tag1": "Compute",
    "CostAllocationRuleName": null,
    "benefitId": null,
    "benefitName": null
  },
  {
    "Tag2": "Microsoft",
    "ChargeType": "Usage",
    "Frequency": "UsageBased",
    "PricingModel": "OnDemand",
    "benefitName": null
  }
]
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
Sathish
  • 31
  • 3

1 Answers1

1

You can use such a shift transformation spec

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "ServiceFamily": "[#2].Tag1",
        "PublisherName": "[#2].Tag2",
        "*": "[#2].&"
      }
    }
  }
]

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

enter image description here

Alternatively you can use the following one which consecutively applies modify and remove transformation specs

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "Tag1": "=(@(1,ServiceFamily))",
        "Tag2": "=(@(1,PublisherName))"
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "*": {
        "ServiceFamily": "",
        "PublisherName": ""
      }
    }
  }
]

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

enter image description here

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55