如何震动通配符工作的RHS?



我想了解'#'通配符的工作原理。

我在准备productList时使用了规范中的"#",它起作用了,我得到了符合我期望的输出。但我不确定它的工作。

谁能帮我了解一下它的工作原理?

这是输入JSON

{
"orders": [
{
"order_parts": [
{
"id": "0001",
"items": [
{
"id": "00101",
"goodIdentificationList": [
{
"goodIdentificationTypeId": "UPCA",
"idValue": "42684666380437"
},
{
"idValue": "V-ASHBY",
"goodIdentificationTypeId": "SHOPIFY_PROD_SKU"
}
],
"productName": "BLACK / 6 / 809"
},
{
"id": "00102",
"goodIdentificationList": [
{
"goodIdentificationTypeId": "SHOPIFY_PROD_ID",
"idValue": "42684666380437"
},
{
"idValue": "V-ASHBY",
"goodIdentificationTypeId": "UPCA"
}
],
"productName": "BLACK / 6 / 809"
}
]
},
{
"id": "0002",
"items": [
{
"id": "00103",
"goodIdentificationList": [
{
"goodIdentificationTypeId": "SHOPIFY_PROD_ID",
"idValue": "42684666380437"
},
{
"idValue": "V-ASHBY",
"goodIdentificationTypeId": "UPCA"
}
],
"productName": "BLACK / 6 / 809"
}
]
}
]
}
]
}

符合以下规范:-

  1. 检查goodidentiationlist的每个映射,获取goodIdentificationTypeId - UPCA所在的idValue,并将productList作为gtin放入。

  2. 从items列表中获取id,并将其作为itemId放入productList中。

  3. 从items列表中获取productName,并将其作为名称放在productList中。

Jolt Spec如下

[
{
"operation": "shift",
"spec": {
"orders": {
"*": {
"order_parts": {
"*": {
"items": {
"*": {
"goodIdentificationList": {
"*": {
"goodIdentificationTypeId": {
"UPCA": {
"@(2,idValue)": "[&5].productList.[#8].gtin"
}
}
}
},
"id": "[&1].productList.[#4].itemId",
"productName": "[&1].productList.[#4].name"
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"productList": {
"*": "productList.[]"
}
}
}
}
]

根据上面的规范,我能够按照我的期望准备productList。
但是我想了解'#'在这里的工作原理。

JSON输出

{
"productList" : [ {
"itemId" : "00101",
"name" : "BLACK / 6 / 809"
}, {
"itemId" : "00103",
"name" : "BLACK / 6 / 809"
}, {
"itemId" : "00102",
"name" : "BLACK / 6 / 809"
} ]
}

任何帮助将不胜感激。谢谢!

您主要需要这个规范

[
{
"operation": "shift",
"spec": {
"order*": {
"*": {
"order*": {
"*": {
"items": {
"*": {
"id": "&3.&1.&",
"prod*": "&3.&1.&"
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "productList[]"
}
}
}
]

其中,"items"数组的索引(&1)与"order_parts"数组的索引(&3)的组合处理了三个单独对象的分离,然后在标记期望值(productList)的同时整理最里面的部分,将这些新生成的对象组合在一起将自发地形成一个数组。

替换

"id": "&3.&1.&",
"prod*": "&3.&1.&"

"id": "&3[&1].&",
"prod*": "&3[&1].&"

"id": "&3[#2].&",
"prod*": "&3[#2].&"

将对当前的情况进行完全相同的处理。但是如果没有数组,标识符[&1][#2]将产生方括号。它们的右手大小使用的不同之处在于[&1]将遍历{,而[#2]将遍历{和当前:字符以达到当前树中的目标,[&1]将使用索引0,1,2,每次都从0开始,这将在某些情况下为生成的数组生成一些空组件,而[#2]不会。如。在规范的RHS上,#仅在数组的上下文中有效,如"[#2]""[#2]"的意思是,向上攀登三个级别(包括当前级别的冒号)并询问该节点有多少匹配,然后将其用作数组中的索引。

最新更新