0
votes

I have a array of Key Value Pairs in my json object, and need to pull out a set value based on the key being equal to host.

{
 "pairs" : [ {
          "key" : "Host",
          "value" : "site-a"
        }, {
          "key" : "User",
          "value" : "user42"
        }
}

I can't match based on position as it could be anywhere in the array of pairs, and the array can vary in size.

My Current Jolt spec looks like, but it's just listing each pair:

[
  {
    "operation": "shift",
    "spec": {
      "requestHeaderFields": {
        "*": {
          "value": "@(1,key)"
        }
      }
    }
  }
]

The current output is:

{
  "Host" : "site-a",
  "User-Agent" : "user42"
}

My desired output would be the following, noting the field name change:

{
  "HostSite" : "site-a",
}

I am wondering if I first need to do a modify-overwrite-beta operation and then a shift?

1

1 Answers

0
votes

This jolt will do the trick. The idea is to check when key has a Host value and then retrieve value:

[
  {
    "operation": "shift",
    "spec": {
      "pairs": {
        "*": {
          "key": {
            "Host": {
              "@(2,value)": "HostSite"
            }
          }
        }
      }
    }
  }
]