简体   繁体   中英

JOLT transformation remove all fields except one

I want to remove all fields from a json except the one named 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. Am I doing something wrong?

Yeah so, "shift" does to support any "regex" matching other than " ", so "^(?!foo). $" is not going to work.

I think you are better off, using "shift" to match "foo" and copy it across to the output. Anyting not matched by the "shift" spec does not get copied across to the output.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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