简体   繁体   中英

Json string to Json using Java and Jolt

I have a json string eg.

 { "value": "{\"userSuspended\":false}" }

What would be the correct Jolt spec to map 'userSuspended' to 'state'?

It needed two transforms and a Javaclass to map the key/value:

  1. Shift "Value":"Value"
  2. Map the keys 'userSuspended' and 'false' through a javaclass to key/value pairs
  3. Shift the output to "userSuspended":"State"

One way of doing it is to split the value and save what you wanted to state.

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "stateArray": "=split('\"',@(1,value))"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "stateArray": {
        "1": "state"
      }
    }
  }
]

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