admin管理员组文章数量:1122832
I have the input JSON
{
"MainObj": {
"SubObject": {
"Invoices": [
{
"InvoiceItemsDetail": [
{
"InvoiceItemLineNumber": "1",
"ItemCode": "122",
"Description": "GoodsDescription1"
},
{
"InvoiceItemLineNumber": "2",
"ItemCode": "222",
"Description": "GoodsDescription2"
}
]
},
{
"InvoiceItemsDetail": [
{
"InvoiceItemLineNumber": "3",
"ItemCode": "322",
"Description": "GoodsDescription3"
},
{
"InvoiceItemLineNumber": "4",
"ItemCode": "422",
"Description": "GoodsDescription4"
}
]
}
]
}
}
}
I require the result which does not contain "AnotherObject" and "SomeOtherObject".
The resultant JSON will contain
InvoiceItemLineNumber
converted toINVOICE_LINE_ITEM_NUMBER
,ItemCode
toITEM_CODE
andDescription
toDESCRIPTION
all of these inside an array of "outputs"
{
"outputs": [
{
"INVOICE_LINE_ITEM_NUMBER": "1",
"ITEM_CODE": "122",
"DESCRIPTION": "GoodsDescription1"
},
{
"INVOICE_LINE_ITEM_NUMBER": "2",
"ITEM_CODE": "222",
"DESCRIPTION": "GoodsDescription2"
},
{
"INVOICE_LINE_ITEM_NUMBER": "3",
"ITEM_CODE": "322",
"DESCRIPTION": "GoodsDescription3"
},
{
"INVOICE_LINE_ITEM_NUMBER": "4",
"ITEM_CODE": "422",
"DESCRIPTION": "GoodsDescription4"
}
]
}
I have the input JSON
{
"MainObj": {
"SubObject": {
"Invoices": [
{
"InvoiceItemsDetail": [
{
"InvoiceItemLineNumber": "1",
"ItemCode": "122",
"Description": "GoodsDescription1"
},
{
"InvoiceItemLineNumber": "2",
"ItemCode": "222",
"Description": "GoodsDescription2"
}
]
},
{
"InvoiceItemsDetail": [
{
"InvoiceItemLineNumber": "3",
"ItemCode": "322",
"Description": "GoodsDescription3"
},
{
"InvoiceItemLineNumber": "4",
"ItemCode": "422",
"Description": "GoodsDescription4"
}
]
}
]
}
}
}
I require the result which does not contain "AnotherObject" and "SomeOtherObject".
The resultant JSON will contain
InvoiceItemLineNumber
converted toINVOICE_LINE_ITEM_NUMBER
,ItemCode
toITEM_CODE
andDescription
toDESCRIPTION
all of these inside an array of "outputs"
{
"outputs": [
{
"INVOICE_LINE_ITEM_NUMBER": "1",
"ITEM_CODE": "122",
"DESCRIPTION": "GoodsDescription1"
},
{
"INVOICE_LINE_ITEM_NUMBER": "2",
"ITEM_CODE": "222",
"DESCRIPTION": "GoodsDescription2"
},
{
"INVOICE_LINE_ITEM_NUMBER": "3",
"ITEM_CODE": "322",
"DESCRIPTION": "GoodsDescription3"
},
{
"INVOICE_LINE_ITEM_NUMBER": "4",
"ITEM_CODE": "422",
"DESCRIPTION": "GoodsDescription4"
}
]
}
Share
Improve this question
edited 7 hours ago
Barbaros Özhan
64.8k11 gold badges35 silver badges61 bronze badges
asked yesterday
user3691240user3691240
572 silver badges9 bronze badges
0
1 Answer
Reset to default 1You just need "*": "[]"
key-value pair as the innermost part of the transformation such as
[
{
"operation": "shift",
"spec": {
"MainObj": {
"SubObject": {
"Invoices": {
"*": {
"InvoiceItemsDetail": {
"*": "[]"
}
}
}
}
}
}
}
]
the demo on the site Jolt Transform Demo Using v0.1.1 is :
EDIT : Rather you can use the following spec, considering that you need to rename the attributes for the new edited case :
[
{ //determine the objects seperated by upper indexes separately
"operation": "shift",
"spec": {
"MainObj": {
"SubObject": {
"Invoices": {
"*": {
"InvoiceItemsDetail": {
"*": {
"Invoice*": "&3_&1.INVOICE_LINE_ITEM_NUMBER",
"Item*": "&3_&1.ITEM_CODE",
"Desc*": "&3_&1.DESCRIPTION"
}
}
}
}
}
}
}
},
{ //get rid of the object keys while adding an array wrapper, namely "outputs"
"operation": "shift",
"spec": {
"*": "outputs[]"
}
}
]
本文标签: Transform JSON using jolt transformationStack Overflow
版权声明:本文标题:Transform JSON using jolt transformation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736281591a1926369.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论