假设您正在尝试转换:
Response from interface 1 = { "A": "value1", "B": "value2", "C": "value3" }
至:
Response from interface 2 = { "Q": "value1", "P": "value2", "R": "value3" }
您可以使用任何执行 JSON 转换的库,例如this或this。例如,您可以像这样定义您的转换:
var template = {
Q: '$.A',
P: '$.B',
R: '$.C'
};
var input = { "A": "value1", "B": "value2", "C": "value3" };
var output = jsonPathObjectTransform(input, template);
// -> output = { "Q": "value1", "P": "value2", "R": "value3" }
将 Java 与Jolt一起使用(我无法对其进行测试,但这是一般的想法):
String input = "{\n" +
" \"A\": \"value1\",\n" +
" \"B\": \"value2\",\n" +
" \"C\": \"value3\"\n" +
"}"
String spec = "[\n" +
" {\n" +
" \"operation\": \"shift\",\n" +
" \"spec\": {\n" +
" \"A\": \"Q\",\n" +
" \"B\": \"P\",\n" +
" \"C\": \"R\"\n" +
" }\n" +
" }\n" +
"]\n"
Chainr chainr = JsonUtils.jsonToList(spec);
Object output = chainr.transform(input);
// -> output = { "Q": "value1", "P": "value2", "R": "value3" }