Json字符串转换为Json使用Java和Jolt

huangapple go评论56阅读模式
英文:

Json string to Json using Java and Jolt

问题

我有一个 JSON 字符串,例如:

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

请问正确的 Jolt 规范是什么,可以将 'userSuspended' 映射到 'state' 吗?

英文:

I have a json string e.g..

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

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

答案1

得分: 1

  1. Shift "Value" to "Value"
  2. 通过一个 Java 类将键 'userSuspended' 和 'false' 映射为键值对
  3. Shift 输出为 "userSuspended" 到 "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"

答案2

得分: 0

一种方法是将值拆分并保存您想要声明的内容。

[
{
"operation": "modify-overwrite-beta",
"spec": {
"stateArray": "=split(''', @(1, value))"
}
},
{
"operation": "shift",
"spec": {
"stateArray": {
"1": "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"
      }
    }
  }
]

huangapple
  • 本文由 发表于 2020年8月11日 20:03:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63357730.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定