-1

Hi pls help with this jolt transformation.

Note:

  1. If Environment exists then add new field numid and value is 1
  2. If costcenter exists then add new field numid and the value is 2

Input:

[
  {
    "Environment": "net",
    "BillingProfileId": 863,
    "ms-resource-usage": "azure-cloud-shell"
  },
  {
    
    "CostCenter": "check",
    "BillingAccountName": "HCL Technologies Ltd.",
    "ServiceFamily": "Compute"
  }
]

Expected output:

[
  {
    "Environment": "net",
    "numid": "1"
    "BillingProfileId": 863,
    "ms-resource-usage": "azure-cloud-shell"
  },
  {
    
    "CostCenter": "check",
   "numid" : "2",
    "BillingAccountName": "HCL Technologies Ltd.",
    "ServiceFamily": "Compute"
  }
]

Thanks

Sathish
  • 31
  • 3

1 Answers1

0

You can use this spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@": "[&1]",
        "Environment": {
          "#1": "[&2].numid"
        },
        "CostCenter": {
          "#2": "[&2].numid"
        }
      }
    }
  }
]
Mohammadreza Khedri
  • 2,523
  • 1
  • 11
  • 22