我需要使用jolt来转换JSON。输入JSON如下:
{
"items": [
{
"Group1": {
"ABCCode": "3",
"ABCDescription": "abcd"
},
"Group2": {
"test2": [
"123"
]
}
}
]
}我需要如下的输出,
[
{
"test2Id": "123",
"attrname": "ABCCode",
"attrval": "3"
},
{
"test2Id": "123",
"attrname": "ABCDescription",
"attrval": "abcd"
}
]如何使用jolt实现这一点?
发布于 2018-02-22 19:20:47
这将从给定的输入中产生输出。您可能需要调整它,因为您为它提供了不同类型的输入。
[
{
"operation": "shift",
"spec": {
"items": {
"*": {
"Group1": {
// match all keys below Group1
"*": {
// "$" means grab the key matched above,
// and write it the the output as "attrname"
"$": "[#2].attrname",
// "@" means grab the value matched above
"@": "[#2].attrval",
// walk back up the match tree three levels
// walk back down the path "Group2.test2[0]"
// and write that value to the output
"@(2,Group2.test2[0])": "[#2].test2Id"
}
}
}
}
}
}
]https://stackoverflow.com/questions/48903290
复制相似问题