Как я могу отфильтровать данные с помощью JOLT Transform несколькими клавишами - PullRequest
0 голосов
/ 06 июня 2018

Я пытаюсь что-то с преобразованием Джолта, но изо всех сил пытаюсь заставить его работать.

Если у меня есть такой ввод:

 {"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

Возможно ли это с преобразованием Джольфа?

1 Ответ

0 голосов
/ 10 июня 2018

Спецификация и комментарий

[
  {
    "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"
      }
    }
  }
]
...