JSON字段用于确定jolt中另一个JSON字段的值

发布于 2025-01-21 07:04:02 字数 854 浏览 3 评论 0原文

假设我们对JSON有

{
  "payments": [
    {
      "paymentId": "16493256102836651255",
      "amount": 9.26,
      "cardType": "DISC",
      "transactionType": "PAYPAL"
    }
  ]
}

期望:

{
  "payment": [
    {
      "paymentId": "16493256102836651255",
      "payment_type": "MTL",
      "transactionType": "REGULAR"
    }
  ]
}

我已经尝试了此规范

[
  {
    "operation": "shift",
    "spec": {
      "payments": {
        "*": {
          "cardType": {
            "LAR": {
              "#MTL": "payment.[].payment_type"
            }
          }
        }
      }
    }
  }
]

,我有更多条件,如果CardType类型是LAR或TrassActionType是PayPal,则应使用MTL映射 如果卡类型是LAR,我可以获得MTL

Let say we have on JSON

{
  "payments": [
    {
      "paymentId": "16493256102836651255",
      "amount": 9.26,
      "cardType": "DISC",
      "transactionType": "PAYPAL"
    }
  ]
}

expected :

{
  "payment": [
    {
      "paymentId": "16493256102836651255",
      "payment_type": "MTL",
      "transactionType": "REGULAR"
    }
  ]
}

I already tried with this spec

[
  {
    "operation": "shift",
    "spec": {
      "payments": {
        "*": {
          "cardType": {
            "LAR": {
              "#MTL": "payment.[].payment_type"
            }
          }
        }
      }
    }
  }
]

I have on more condition that if cardType type is LAR or transactionType is PAYPAL then is should map with MTL
I am able to get the MTL if card type is LAR but need to check if LAR is not card type but transaction type is PAYPAL then also it should so MTL

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨后彩虹 2025-01-28 07:04:02

您可以将单个条件用作每个每个对象(cardTypetransactionType),例如

[
  {
    "operation": "shift",
    "spec": {
      "payments": {
        "*": {
          "paymentId": "payment[&1].&",
          "cardType": {
            "LAR": {
              "#MTL": "payment[&3].payment_type[]",
              "#REGULAR": "payment[&3].transactionType"
            }
          },
          "transactionType": {
            "PAYPAL": {
              "#MTL": "payment[&3].payment_type[]",
              "#REGULAR": "payment[&3].transactionType"
            }
          }
        }
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "*": {
          "*": "ONE"
        }
      }
    }
  }
]

网站上的 demo http://jolt-demo.appspot.com/

You can use individual conditional as objects per each one (cardType and transactionType) such as

[
  {
    "operation": "shift",
    "spec": {
      "payments": {
        "*": {
          "paymentId": "payment[&1].&",
          "cardType": {
            "LAR": {
              "#MTL": "payment[&3].payment_type[]",
              "#REGULAR": "payment[&3].transactionType"
            }
          },
          "transactionType": {
            "PAYPAL": {
              "#MTL": "payment[&3].payment_type[]",
              "#REGULAR": "payment[&3].transactionType"
            }
          }
        }
      }
    }
  },
  {
    "operation": "cardinality",
    "spec": {
      "*": {
        "*": {
          "*": "ONE"
        }
      }
    }
  }
]

the demo on the site http://jolt-demo.appspot.com/ is

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文