基于匹配条件的JOLT变换

时间:2019-03-06 15:25:27

标签: json jolt

我正在尝试根据匹配条件使用JSONJSON转换为JOLT

如果'type':'true',则进行处理。

JSON输入:

{
     "features": [
        {
           "type": "true",
           "properties": {
           "class_lvl": "U",
           "image_url": [
              "http://www.google.com/149231_294002.jpg",
              "https://www.google.com/149231_294002.jpg"
           ],
           "review_date": "2019-03-27T15:42:02.523"              
         }
      }
    ]
  }

我想到的JOLT规范并未按照我想要的方式生成:

 [
      {
          "operation": "shift",
          "spec": {
          "features": {
            "*": {
              "properties": {            
               //go up one level and check if type = true then copy image URL
                "@(1,type)": {              
                  "true": {
                    "image_url": "Parent[&3].child.grandchild"
                  }
                }
              }
            }
          }
        }
      }
   ] 

1 个答案:

答案 0 :(得分:0)

此规范有效:

[
  {
    "operation": "shift",
    "spec": {
      "features": {
        "*": {
          //"type": "Parent[#].child.grandchild.type",
          "properties": {
            //go up one level and check if type = true then copy image URL
            "@(1,type)": {
              "true": {
                "@2": "Parent[#].child.grandchild"
              }
            }
          }
        }
      }
    }
  }
  ]