【问题标题】:Jolt Spec for masking cards用于遮蔽卡的 Jolt 规格
【发布时间】:2023-01-12 06:10:37
【问题描述】:

如何遍历列表并替换其中的一些元素? 我有这个输入

{
  "clients": [
    {
      "clientId": "166734",
      "info": {
        "cards": [
          "378282246310005",
          "371449635398431"
        ]
      }
    }
  ]
}

我希望卡片看起来像这样"cards" : [ "3782", "3714" ]

但在我的规范中,子字符串不起作用

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "clients": {
        "*": {
          "info": {
            "cards": {
              "*": "=substring(@(1,&),0,@(1,4))"
            }
          }
        }
      }
    }
  }
]

【问题讨论】:

    标签: json regex mask jolt


    【解决方案1】:

    您可以使用转移转换以驯服卡片阵列以准备调整转换规范,例如

    [
      {
        "operation": "shift",
        "spec": {
          "clients": {
            "*": {
              "*": "&2[#2].&",
              "info": {
                "cards": {
                  "*": {
                    "@": "&5[#5].&3.&2.&"
                  }
                }
              }
            }
          }
        }
      },
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "clients": {
            "*": {
              "info": {
                "cards": {
                  "*": "=substring(@(1,&),0,4)"
                }
              }
            }
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "clients": {
            "*": {
              "*": "&2[#2].&",
              "info": {
                "cards": {
                  "*": "&4[#4].&2.&1[#1]"
                }
              }
            }
          }
        }
      }
    ]
    

    如果总是只能存在两个分量然后我们通过使用使整个规范更短[第一个/最后一个]元素功能如

    [
      {
        "operation": "modify-overwrite-beta",
        "spec": {
          "clients": {
            "*": {
              "info": {
                "c0": "=firstElement(@(1,cards))",
                "c1": "=lastElement(@(1,cards))",
                "cards0": "=substring(@(1,c0),0,4)",
                "cards1": "=substring(@(1,c1),0,4)"
              }
            }
          }
        }
      },
      {
        "operation": "shift",
        "spec": {
          "clients": {
            "*": {
              "*": "&2[#2].&",
              "info": {
                "*s*": "&3[#3].&1.&(0,1)s"
              }
            }
          }
        }
      }
    ]
    

    【讨论】:

      猜你喜欢
      • 2011-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-12
      • 2021-12-07
      • 2016-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多