简体   繁体   中英

JOLT transformation JSON to array

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

Just found how to do that !

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM