json - 如何通过几个键使用 JOLT Transform 过滤数据
问题描述
我正在尝试使用 Jolt 转换,但努力让它发挥作用。
如果我有这样的输入:
{"options": [
{
"id": "18031",
"name": "sample",
"archived": true,
"released": true,
"releaseDate": "2014-11-04",
"userReleaseDate": "04 Nov 2014",
"projectId": 13001
},
{
"id": "231418",
"description": "service_release",
"name": "3.07.17",
"archived": false,
"flag_m": true,
"releaseDate": "2017-07-03",
"userReleaseDate": "03 Jul 2017",
"projectId": 13001
},
{
"id": "249700",
"description": "service_release",
"name": "service-09.02.18",
"archived": false,
"flag_m": false,
"startDate": "2018-02-09",
"userStartDate": "09 Feb 2018",
"projectId": 13001
}]}
我希望输出为:
{
"options" : [
{
"value" : "service-09.02.18",
"key" : "service-09.02.18"
},
{
"value" : "3.07.17",
"key" : "3.07.17"
}
]
}
仅适用于 flag_m=false 和 description=service_release 的对象
Jolf 变换有可能吗?
解决方案
规格和评论
[
{
"operation": "shift",
"spec": {
"options": {
"*": {
"flag_m": {
"false": {
// match 'flag_m = false', and if we get
// here, reset up the tree so we can
// check 'description = service_release'
"@2": {
"description": {
"service_release": {
// If we matched all the way down here,
// then reset up again, and grab the data.
"@5": {
// Your example output did not make sense to me.
// Assuming you want the id as a "key",
// and the name as "value"
//
// This builds two parallel arrays in the
// output, that we can pivot in the next
// step.
//
"name": "values[]",
"id": "keys[]"
}
}
}
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"keys": {
"*": "options[&].key"
},
"values": {
"*": "options[&].value"
}
}
}
]
推荐阅读
- python - How to load fancyimpute in python?
- c# - Change element position when hidden inside a StackPanel
- sql-server - sqlcmd running into unicode conversion issues on SLES12SP5
- azure-devops - Azure DevOps YAML how to being notified about new task version
- python - Replacing a decoder linear layer with an LSTM
- angular-material - 【Angular Material】How to place two
in the same horizontal, and one with mat-stretch-tabs directive - java - IntelliJ Idea keeps switching project windows on desktop change
- python - 搭建端到端的数据分析平台
- sql - 在同一张表上使用 4 个内部连接加速 sql 查询?
- git - 如何使用 VS Code 将项目发布到现有的 Github 存储库