简体   繁体   English

JOLT转换删除除一个字段外的所有字段

[英]JOLT transformation remove all fields except one

I want to remove all fields from a json except the one named foo . 我想从json中删除除名为foo之外的所有字段。 I used transformation spec as given below: 我使用了如下的转换规范:

[
  {
    "operation": "remove",
    "spec": {
      "^(?!foo).*$": ""
    }
  }
]

I tried executing this on http://jolt-demo.appspot.com/#inception but it doesn't work and it outputs the input json, untransformed. 我尝试在http://jolt-demo.appspot.com/#inception上执行此操作,但是它不起作用,并且会输出未转换的输入json。 Am I doing something wrong? 难道我做错了什么?

Yeah so, "shift" does to support any "regex" matching other than " ", so "^(?!foo). $" is not going to work. 是的,“ shift”支持除“ 之外的任何“ regex”匹配,因此“ ^(?! foo)。 $”无效。

I think you are better off, using "shift" to match "foo" and copy it across to the output. 我认为您最好,使用“ shift”匹配“ foo”并将其复制到输出中。 Anyting not matched by the "shift" spec does not get copied across to the output. 与“ shift”规范不匹配的任何内容都不会复制到输出中。

Spec 规格

[
  {
    "operation": "shift",
    "spec": {
      // matches top level key "foo" in the intput, and copies the 
      //  value at that location to the output map with key "foo".
      "foo" : "foo"
    }
  }
]

Shift copies data from the input to a new ouput, all the other operations (default, remove, cardinality, etc) modify the input. Shift将数据从输入复制到新的输出,所有其他操作(默认,删除,基数等)都会修改输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM