如何从Jolt规范中的字符串中删除单引号

huangapple go评论58阅读模式
英文:

How to remove single quotes from string in Jolt Spec

问题

以下是已翻译好的部分:

输入

{
  "text": "2023-05-24 12:11:06.185 google.com i-axcel: phone 'New Launch of software city' on USKANSAS changed from USNYC"
}

Jolt 规范

[
  {
    "operation": "shift",
    "spec": {
      "text": ["description_cpy2"]
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "description_cpy2": "=split('phone', @(1, description_cpy2))",
      "pharse": "=split('changed', @(1, description_cpy2[1]))",
      "pharseone": "@(1, pharse[0])",
      "pharsetwo": "@(1, pharse[0])"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "pharseone": "=trim",
      "pharsetwo": "=trim"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "pharseone": "pharseone",
      "pharsetwo": "pharsetwo"
    }
  }
]

当前输出

{
  "pharseone" : "'New Launch of software city' on USKANSAS",
  "pharsetwo" : "'New Launch of software city' on USKANSAS"
}

期望输出

{
  "pharseone" : "New Launch of software city on USKANSAS",
  "pharsetwo" : "New Launch of software city on USKANSAS"
}

如果您需要更多帮助,请随时告诉我。

英文:

I am phrasing the value of a long string where the data comes with single quotes ('). how we can remove the single quotes in Jolt Specification. Please suggest.

Input :

{
  "text": "2023-05-24 12:11:06.185 google.com i-axcel: phone 'New Launch of software city' on USKANSAS changed from USNYC"
}

Jolt Spec :

[
  {
    "operation": "shift",
    "spec": {
      "text": ["description_cpy2"]
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "description_cpy2": "=split('phone',@(1,description_cpy2))",
      "pharse": "=split('changed',@(1,description_cpy2[1]))",
      "pharseone": "@(1,pharse[0])",
      "pharsetwo": "@(1,pharse[0])"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "pharseone": "=trim",
      "pharsetwo": "=trim"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "pharseone": "pharseone",
      "pharsetwo": "pharsetwo"
    }
  }
]

Current Output :

{
  "pharseone" : "'New Launch of software city' on USKANSAS",
  "pharsetwo" : "'New Launch of software city' on USKANSAS"
}

Expected output :

{
  "pharseone" : "New Launch of software city on USKANSAS",
  "pharsetwo" : "New Launch of software city on USKANSAS"
}

答案1

得分: 3

它在Jolt中没有直接的函数方式,但你可以使用shift操作来单独获取'并将其删除。

[
  {
    "operation": "shift",
    "spec": {
      "text": ["description_cpy2"]
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "description_cpy2": "=split('phone', @(1, description_cpy2))",
      "pharse": "=split('changed', @(1, description_cpy2[1]))",
      "pharseone": "@(1, pharse[0])",
      "pharsetwo": "@(1, pharse[0])"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "pharseone": "=trim",
      "pharsetwo": "=trim",
      "pharseon*": "=split('', @(1, pharseone))",
      "pharsetw*": "=split('', @(1, pharsetwo))"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "pharse*": {
        "*": {
          "'": {
            "@1": "temp_&3"
          },
          "*": {
            "@1": "&3"
          }
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "temp_*": ""
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=join('', @(1, &))"
    }
  }
]
英文:

It doesn't have a straight way with functions in Jolt, But you can use the shift operation to get ' separately and remove them.

[
  {
    "operation": "shift",
    "spec": {
      "text": ["description_cpy2"]
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "description_cpy2": "=split('phone',@(1,description_cpy2))",
      "pharse": "=split('changed',@(1,description_cpy2[1]))",
      "pharseone": "@(1,pharse[0])",
      "pharsetwo": "@(1,pharse[0])"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "pharseone": "=trim",
      "pharsetwo": "=trim",
      "pharseon*": "=split('',@(1,pharseone))",
      "pharsetw*": "=split('',@(1,pharsetwo))"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "pharse*": {
        "*": {
          "'": {
            "@1": "temp_&3"
          },
          "*": {
            "@1": "&3"
          }
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "temp_*": ""
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=join('',@(1,&))"
    }
  }
]

huangapple
  • 本文由 发表于 2023年5月25日 00:42:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76325759.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定