如何解决需要 Jolt Spec 将矩阵 json 转换为非规范化的 json 格式
任何人都可以帮我一个 JOLT 规范 将我的矩阵类型 json 转换为非规范化 json。请在下面找到我的输入 json 和我预期的 josn 输出。
输入 Json:
go run main.go
预期的 Json 输出:
[
{
"attributes": [
{
"name": "brand","value": "Patriot Lighting"
},{
"name": "color","value": "Chrome"
},{
"name": "price","value": "49.97 USD"
}
]
},{
"attributes": [
{
"name": "brand","value": "Masterforce"
},"value": "Green"
},"value": "99.0 USD"
}
]
}
]
我试图构建 JOLT 规范来转换这个 json。但挑战是我有多个带有“属性”标签的表的 json。
提前致谢!
解决方法
JOLT 不容易使用,但我从其他一些 StackOverflow 问题中得到了很多,我刚刚开始阅读 the source code comments
[
{
"operation": "shift","spec": {
// for each element in the array
"*": {
"attributes": {
// for each element in the attribute
"*": {
// grab the value
// - put it in an array
// - but it must be indexed by the "positions" found four steps back
// - put the value in a key
// - that is determined by moving one step back and looking at member name
"value": "[#4].@(1,name)"
}
}
}
}
}
]
这乍一看似乎很晦涩,但我希望评论能解释一切。
请继续阅读JOLT transformation to copy single value along an array
这对于 JOLT 初学者来说几乎是强制性的https://docs.google.com/presentation/d/1sAiuiFC4Lzz4-064sg1p8EQt2ev0o442MfEbvrpD1ls/edit#slide=id.g9a487080_011
如果你需要另一个例子,我刚刚在这里回答了一个问题Nifi JOLT: flat JSON object to a list of JSON object
而且,您最好的朋友可能在 https://jolt-demo.appspot.com
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。