JOLT transformation JSON to array

61 views Asked by At

I have to tranform a JSON input to a an array containing one objet.
I have this JOLT configuration:

[
  {
    "operation": "shift",
    "spec": {
      "tokenType": "key",
      "accessToken": "value"
    }
  }
]

Here's my input:

{
  "tokenType": "Bearer",
  "refreshToken": "xxx.xxx.xxx",
  "accessToken": "yyy.yyy.yyy",
  "signature": "secret",
  "links": {
    "href": "someLink",
    "refreshTokenHref": "someLink",
    "signoutHref": "someLink"
  },
  "version": "1.0"
}

Actual output:

{
  "key" : "Bearer",
  "value" : "yyy.yyy.yyy"
}

Desired output:

[{
  "key" : "Bearer",
  "value" : "yyy.yyy.yyy"
}]

Do you have any idea how to do that ?

Thx for your help guys

1

There are 1 answers

0
tabary Romain On

Just found how to do that !

[
  {
    "operation": "shift",
    "spec": {
      "accessToken": {
        "$": "[#2].key",
        "@": "[#2].value"
      }
    }
  }
]