Jolt 将对象列表转换为数组
Jolt converts list of Objects to Arrays
我是新手。我试图实现的转变实际上是 simple.I 有一个 json,如下所示
{
"Object": [
{
"date": "01-01-2021",
"Sold": {
"ItemType": "New",
"ItemID": 1,
"Description": "desc 1"
}
},
{
"date": "01-01-2021",
"Sold": {
"ItemType": "New 2",
"ItemID": 2,
"Description": "desc 2"
}
}
]
}
我的预期输出是
[{
"ItemType": "New",
"ItemID": 1,
}
,{
"ItemType": "New 2",
"ItemID": 2,
}]
但是当我使用这个转换时
[
{
"operation": "shift",
"spec": {
"Object": {
"*": {
"Sold": {
"ItemType": "ItemType"
}
}
}
}
}
]
我得到的输出是
{
"ItemType" : [ "New", "New 2" ]
}
我犯了什么错误?
您应该阅读有关在 JSON 数组 here for example 上应用 JOLT 的内容。
您需要使用 [&2] 引用索引数组,这意味着查找树的三个级别:零(对象),然后是一个(已售出),然后是两个(ItemType/ItemID),并将其用作索引数组输出。
[
{
"operation": "shift",
"spec": {
"Object": {
"*": {
"Sold": {
"ItemType": "[&2].ItemType",
"ItemID": "[&2].ItemID"
}
}
}
}
}
]
输出:
[ {
"ItemType" : "New",
"ItemID" : 1
}, {
"ItemType" : "New 2",
"ItemID" : 2
} ]
我是新手。我试图实现的转变实际上是 simple.I 有一个 json,如下所示
{
"Object": [
{
"date": "01-01-2021",
"Sold": {
"ItemType": "New",
"ItemID": 1,
"Description": "desc 1"
}
},
{
"date": "01-01-2021",
"Sold": {
"ItemType": "New 2",
"ItemID": 2,
"Description": "desc 2"
}
}
]
}
我的预期输出是
[{
"ItemType": "New",
"ItemID": 1,
}
,{
"ItemType": "New 2",
"ItemID": 2,
}]
但是当我使用这个转换时
[
{
"operation": "shift",
"spec": {
"Object": {
"*": {
"Sold": {
"ItemType": "ItemType"
}
}
}
}
}
]
我得到的输出是
{
"ItemType" : [ "New", "New 2" ]
}
我犯了什么错误?
您应该阅读有关在 JSON 数组 here for example 上应用 JOLT 的内容。 您需要使用 [&2] 引用索引数组,这意味着查找树的三个级别:零(对象),然后是一个(已售出),然后是两个(ItemType/ItemID),并将其用作索引数组输出。
[
{
"operation": "shift",
"spec": {
"Object": {
"*": {
"Sold": {
"ItemType": "[&2].ItemType",
"ItemID": "[&2].ItemID"
}
}
}
}
}
]
输出:
[ {
"ItemType" : "New",
"ItemID" : 1
}, {
"ItemType" : "New 2",
"ItemID" : 2
} ]