json - 需要 Jolt Spec 将矩阵 json 转换为非规范化 json 格式
问题描述
谁能帮我一个JOLT 规范,将我的矩阵类型 json 转换为非规范化 json。请在下面找到我的输入 json 和我预期的 josn 输出。
输入Json:
[
{
"attributes": [
{
"name": "brand",
"value": "Patriot Lighting"
},
{
"name": "color",
"value": "Chrome"
},
{
"name": "price",
"value": "49.97 USD"
}
]
},
{
"attributes": [
{
"name": "brand",
"value": "Masterforce"
},
{
"name": "color",
"value": "Green"
},
{
"name": "price",
"value": "99.0 USD"
}
]
}
]
预期的 Json 输出:
[
{
"brand": "Patriot Lighting",
"color": "Chrome",
"price": "49.97 USD"
},
{
"brand": "Masterforce",
"color": "Green",
"price": "99.0 USD"
}
]
我试图构建 JOLT 规范来转换这个 json。但挑战是我有多个带有“属性”标签的表的 json。
提前致谢!
解决方案
JOLT 不容易使用,但我从其他一些 StackOverflow 问题中得到了很多,我刚刚开始阅读源代码注释
[
{
"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 初学者来说几乎是强制性的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找到
推荐阅读
- firebase - 有没有办法用 Firestore 中的数据制作带有 Checkbox 的 FlutterFormBuilder?
- c# - FluentValidation 如何验证孙子
- python-3.x - ValueError:无法将字符串转换为浮点数:'21,7'
- python - 如何根据另一个文件名文件夹重命名文件夹中的所有文件名?
- .net - 无法使用 Visual Studio 2019 构建 F# 项目
- google-cloud-platform - 使用 Spark Big Query 连接器的自定义 SQL
- python - 如何将字典附加到字典字典
- firebase - 如何根据用户注册的位置设置不同的自定义声明?
- c++ - C++ 可变参数模板推导失败
- mongodb - 存储在地图中的数据,需要数组中所有对象的所有值