英文:
How to compare two string values in jolt
问题
-
如果 from_Store 和 to_Store 的值不匹配,则在输出 JSON 中保留该映射的完整元素。
-
如果值匹配,则整个元素不应包含在输出中。
期望的输出 JSON
[
{
"from_Store": "Test2",
"to_Store": "Test3",
"items": [
{
"UPC": "8240959370210",
"shippedQuantity": 1
}
]
}
]
在 Jolt 中是否有比较字符串的函数?
英文:
I want to filter out the input JSON based on two field values of input JSON.
Input JSON
[
{
"from_Store": "Test1",
"to_Store": "Test1",
"items": [
{
"UPC": "8240959370255",
"shippedQuantity": 1
}
]
},
{
"from_Store": "Test2",
"to_Store": "Test3",
"items": [
{
"UPC": "8240959370210",
"shippedQuantity": 1
}
]
}
]
- If the values of the from_Store and to_Store do not match, then keep that complete element of the map in the output JSON.
- If the values match, then the entire element should not be in the output
Expected output JSON
[
{
"from_Store": "Test2",
"to_Store": "Test3",
"items": [
{
"UPC": "8240959370210",
"shippedQuantity": 1
}
]
}
]
Is there any function to compare the strings in Jolt?
Any help would be appreciated!
答案1
得分: 1
你可以为每个节点交换to_Store
和from_Store
属性的键值对,无论是否形成数组。如果形成数组,那么我们将只获得1个元素,例如,属性的值相等。否则,我们将获得2个元素,因此,我们将它们保留为结果,例如
[
{
"operation": "shift",
"spec": {
"*": {
"*_*": "Cnt[&1].Count.@0" // 用唯一的下划线代表两个属性,例如 "from_store" 和 "to_store"
},
"@": "Original" // 复制初始 JSON 值
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"Cnt": {
"*": {
"Count": "=size(@(1,&))"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"Count": "&1",
"*": "&1.&"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"1": { // 第二个组件
"2": { // 保留值如果它的值是 2
"@(2,[0])": "[]"
}
}
}
}
}
]
在网站http://jolt-demo.appspot.com/上的演示如下:
英文:
You can exchange key-value pairs for to_Store
and from_Store
attributes whether an array is formed or not per each node. If array is formed, then we'll get only 1 element, eg. values of the attributes are equal. Otherwise, we'll get 2 elements, so, we'll keep them as result such as
[
{
"operation": "shift",
"spec": {
"*": {
"*_*": "Cnt[&1].Count.@0" // to represent both of the attributes with unique underscores, eg. "from_store" and "to_store"
},
"@": "Original" // replicate the initial JSON value
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"Cnt": {
"*": {
"Count": "=size(@(1,&))"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"Count": "&1",
"*": "&1.&"
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"1": { // the second component
"2": { // keep the value if its value is 2
"@(2,[0])": "[]"
}
}
}
}
}
]
the demo on the site http://jolt-demo.appspot.com/ is
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论