我正在尝试与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转型有关吗?
答案 0 :(得分:0)
规范和评论
[
{
"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"
}
}
}
]