-1

pls help me out wit this jolt specification. pls help me

Notes :

  1. Resourcename is the last element of ResourceId which will be a new attribute that we need to add to the expected output

  2. Tags field needs to be copied and splited as mentioned in the expected output.

Input :

[
  {
    "ResourceId": "/subscriptions/bb842437aa4/resourceGroups/ECHLABHENKEL/providers/Microsoft.Compute/virtualMachines/pmoapps",
    "Tags": "Name\": \"PMOapplication\",\"Owner\": \"Breil sathish"
  },
  {
    "ResourceId": "/subscriptions/bb842437aa4/resourceGroups/HCLTECHLABHENKEL/providers/Microsoft.Compute/virtualMachines/pmoapps",
    "Tags": "Name\": \"PMOapplication\",\"Owner\": \"Breil sathish1"
  }
]

Expected Output :

[
  {
    "ResourceId": "/subscriptions/bb842437aa4/resourceGroups/ECHLABHENKEL/providers/Microsoft.Compute/virtualMachines/pmoapps",
    "Tags": "Name\": \"PMOapplication\",\"Owner\": \"Breil sathish",
    "Resourcename": "pmoapps",
    "Name": "PMOapplication",
    "Owner": "Breil sathish"
  },
  {
    "ResourceId": "/subscriptions/bb842437aa4/resourceGroups/HCLTECHLABHENKEL/providers/Microsoft.Compute/virtualMachines/pmoapps",
    "Tags": "Name\": \"PMOapplication\",\"Owner\": \"Breil sathish1",
    "Resourcename": "pmoapps",
    "Name": "PMOapplication",
    "Owner": "Breil sathish1"
  }
]

Thanks, N Sathish

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

1 Answers1

1

You can use the following transformation spec as reading the explanations stated at the beginning of each of them such as

[
  { // Convert the value of the attributes to individual arrays with the identical names
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "ResourceName": "=split('/', @(1,ResourceId))",
        "tag": "=split(',', @(1,Tags))"
      }
    }
  },
  { // Generate tag0 and tag1 attributes by splitting members of the "tag" array
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&1.&",
        "tag": {
          "*": {
            "@": "&3.&2&1"
          }
        }
      }
    }
  },
  { // Split related strings by colon characters for "tag" array while deriving the last element of "ResourceName" array
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "R*": "=lastElement(@(1,&))",
        "tag*": "=split(': ', @(1,&))"
      }
    }
  },
  { // Match components of "tag" array component 1 against component 2
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&1.&",
        "tag*": {
          "@1,&[1]": "&2.&1.@(2,&[0])"
        }
      }
    }
  },
  { // Split the values by \" character combination 
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "tag*": {
          "*": "=split('\"', @(1,&))"
        }
      }
    }
  },
  { // Prune undesired values for right-hand-side
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "tag*": {
          "*": "=join('', @(1,&))"
        }
      }
    }
  },
  { // Prune undesired values for left-hand-side(keys)
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[&1].&",
        "tag*": {
          "\"*\"": "[&2].&(0,1)",
          "*\"": "[&2].&(0,1)"
        }
      }
    }
  }
]
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55