简体   繁体   English

Json 字符串到 Json 使用 Java 和 Jolt

[英]Json string to Json using Java and Jolt

I have a json string eg.我有一个 json 字符串,例如。

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

What would be the correct Jolt spec to map 'userSuspended' to 'state'? map 'userSuspended' 到 'state' 的正确 Jolt 规范是什么?

It needed two transforms and a Javaclass to map the key/value:它需要两个转换和一个 Java 类来 map 键/值:

  1. Shift "Value":"Value"转移“价值”:“价值”
  2. Map the keys 'userSuspended' and 'false' through a javaclass to key/value pairs Map 通过 javaclass 到键/值对的键 'userSuspended' 和 'false'
  3. Shift the output to "userSuspended":"State"将 output 转换为“userSuspended”:“State”

One way of doing it is to split the value and save what you wanted to state.一种方法是拆分值并将您想要的内容保存到 state。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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