英文:
Remove escape characters from string using JOLT
问题
以下是您要翻译的内容:
The output I'm getting:
[
{
"MiddleName": "Gisela\\\"mn"
},
{
"MiddleName": "Gisela12"
}
]
The output I need:
[
{
"MiddleName": "Giselamn"
},
{
"MiddleName": "Gisela12"
}
]
英文:
I'm trying to use replace function to remove the special characters, but the escape characters are not being removed.
Input:
[
{
"MiddleName": "Gisela\"mn"
},
{
"MiddleName": "Gisela12---"
}
]
Spec:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"MiddleName": "=replace('(\\-\\s*)|\\s+--',@(1,MiddleName))"
}
}
}
]
The output I'm getting:
[
{
"MiddleName": "Gisela\"mn"
},
{
"MiddleName": "Gisela12"
}
]
The output I need:
[
{
"MiddleName": "Giselamn"
},
{
"MiddleName": "Gisela12"
}
]
答案1
得分: 1
你可以连续使用split和join函数,例如
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=split('\"',@(1,&))"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=join('',@(1,&))"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=split('-',@(1,&))"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=join('',@(1,&))"
}
}
}
]
英文:
You can consecutively use split and join functions such as
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=split('\"',@(1,&))"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=join('',@(1,&))"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=split('-',@(1,&))"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=join('',@(1,&))"
}
}
}
]
答案2
得分: 1
你可以使用更简单的方式,如下所示的规范:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"MiddleName_temp1": "=split('\"', @(1, MiddleName))",
"MiddleName_temp2": "=join('', @(1, MiddleName_temp1))",
"MiddleName_temp3": "=split('-', @(1, MiddleName_temp2))",
"MiddleName": "=join('', @(1, MiddleName_temp3))"
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"MiddleName*": ""
}
}
}
]
英文:
You can use simpler way like this spec:
[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"MiddleName_temp1": "=split('\"',@(1,MiddleName))",
"MiddleName_temp2": "=join('',@(1,MiddleName_temp1))",
"MiddleName_temp3": "=split('-',@(1,MiddleName_temp2))",
"MiddleName": "=join('',@(1,MiddleName_temp3))"
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"MiddleName*": ""
}
}
}
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论