移除值等于某物时的震动物体

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

Jolt Removing Object when value is Equal to Something

问题

以下是您提供的内容的中文翻译:

我有这样的输入 -

```json
[
  {
    "time": "2014-10-31T01:59:59.000+10:00",
    "value": {
      "nil": null
    },
    "metadata": {
      "TVPMeasurementMetadata": {
        "qualifier": {
          "title": null,
          "href": null
        }
      }
    },
    "longitude": "115.1248985",
    "latitude": "-33.963617",
    "gathered_time": "1685662804091"
  },
  {
    "time": "2014-11-30T02:00:00.000+10:00",
    "value": {
      "nil": null
    },
    "metadata": {
      "TVPMeasurementMetadata": {
        "qualifier": {
          "title": null,
          "href": null
        }
      }
    },
    "longitude": "115.1248985",
    "latitude": "-33.963617",
    "gathered_time": "1685662804091"
  },
  {
    "time": "2014-12-10T02:00:00.000+10:00",
    "value": 83.939,
    "metadata": null,
    "longitude": "115.1248985",
    "latitude": "-33.963617",
    "gathered_time": "1685662804091"
  },
  {
    "time": "2014-12-11T02:00:00.000+10:00",
    "value": 84.089,
    "metadata": null,
    "longitude": "115.1248985",
    "latitude": "-33.963617",
    "gathered_time": "1685662804091"
  }
]

我想要的是只获取JSON对象中包含数字数据且不等于 {"nil": null} 的值... 以下是预期的输出:

[
    {
      "time" : "2014-12-10T02:00:00.000+10:00",
      "value" : 83.939,
      "metadata" : null,
      "longitude" : "115.1248985",
      "latitude" : "-33.963617",
      "gathered_time" : "1685662804091"
    }, {
      "time" : "2014-12-11T02:00:00.000+10:00",
      "value" : 84.089,
      "metadata" : null,
      "longitude" : "115.1248985",
      "latitude" : "-33.963617",
      "gathered_time" : "1685662804091"
    }
]

我尝试了一些不同的规格操作,如删除,但那些并没有帮助我。


<details>
<summary>英文:</summary>

I have an input like this -

[
{
"time": "2014-10-31T01:59:59.000+10:00",
"value": {
"nil": null
},
"metadata": {
"TVPMeasurementMetadata": {
"qualifier": {
"title": null,
"href": null
}
}
},
"longitude": "115.1248985",
"latitude": "-33.963617",
"gathered_time": "1685662804091"
},
{
"time": "2014-11-30T02:00:00.000+10:00",
"value": {
"nil": null
},
"metadata": {
"TVPMeasurementMetadata": {
"qualifier": {
"title": null,
"href": null
}
}
},
"longitude": "115.1248985",
"latitude": "-33.963617",
"gathered_time": "1685662804091"
},
{
"time": "2014-12-10T02:00:00.000+10:00",
"value": 83.939,
"metadata": null,
"longitude": "115.1248985",
"latitude": "-33.963617",
"gathered_time": "1685662804091"
},
{
"time": "2014-12-11T02:00:00.000+10:00",
"value": 84.089,
"metadata": null,
"longitude": "115.1248985",
"latitude": "-33.963617",
"gathered_time": "1685662804091"
}
]


What I want is to only get values the JSON objects that have numerical data in them and don&#39;t equal  {&quot;nil&quot;: null} ... Here&#39;s what the expected output looks like.

[
{
"time" : "2014-12-10T02:00:00.000+10:00",
"value" : 83.939,
"metadata" : null,
"longitude" : "115.1248985",
"latitude" : "-33.963617",
"gathered_time" : "1685662804091"
}, {
"time" : "2014-12-11T02:00:00.000+10:00",
"value" : 84.089,
"metadata" : null,
"longitude" : "115.1248985",
"latitude" : "-33.963617",
"gathered_time" : "1685662804091"
}
]


I tried a couple different specs operations like remove but those didn&#39;t get me anywhere. 


</details>


# 答案1
**得分**: 3

```json
[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "value": {
          "nil": {
            "null": {
              "": ""
            }
          },
          "*": {
            "@2": ""
          }
        }
      }
    }
  }
]
英文:
[
  {
    &quot;operation&quot;: &quot;shift&quot;,
    &quot;spec&quot;: {
      &quot;*&quot;: {
        &quot;value&quot;: {
          &quot;nil&quot;: {
            &quot;null&quot;: {
              &quot;&quot;: &quot;&quot;
            }
          },
          &quot;*&quot;: {
            &quot;@2&quot;: &quot;&quot;
          }
        }
      }
    }
  }
]

答案2

得分: 0

这是您的 Jolt 规范:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "value_temp": "@(1,value)",
        "value_tem*": ["=toInteger", "null"]
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "value_temp": {
          "*": {
            "@2": "data.&1"
          }
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "data": {
        "null": "",
        "*": {
          "value_temp": ""
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": "[#2].&"
        }
      }
    }
  }
]
英文:

This is your Jolt spec:

[
  {
    &quot;operation&quot;: &quot;modify-overwrite-beta&quot;,
    &quot;spec&quot;: {
      &quot;*&quot;: {
        &quot;value_temp&quot;: &quot;@(1,value)&quot;,
        &quot;value_tem*&quot;: [&quot;=toInteger&quot;, &quot;null&quot;]
      }
    }
  },
  {
    &quot;operation&quot;: &quot;shift&quot;,
    &quot;spec&quot;: {
      &quot;*&quot;: {
        &quot;value_temp&quot;: {
          &quot;*&quot;: {
            &quot;@2&quot;: &quot;data.&amp;1&quot;
          }
        }
      }
    }
  },
  {
    &quot;operation&quot;: &quot;remove&quot;,
    &quot;spec&quot;: {
      &quot;data&quot;: {
        &quot;null&quot;: &quot;&quot;,
        &quot;*&quot;: {
          &quot;value_temp&quot;: &quot;&quot;
        }
      }
    }
  },
  {
    &quot;operation&quot;: &quot;shift&quot;,
    &quot;spec&quot;: {
      &quot;*&quot;: {
        &quot;*&quot;: {
          &quot;*&quot;: &quot;[#2].&amp;&quot;
        }
      }
    }
  }
]

huangapple
  • 本文由 发表于 2023年6月2日 08:03:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76386415.html
匿名

发表评论

匿名网友

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

确定