代码之家  ›  专栏  ›  技术社区  ›  ishan3243

抖动变换删除除一个字段外的所有字段

  •  1
  • ishan3243  · 技术社区  · 7 年前

    我想删除json中除名为 foo

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

    我试着在 http://jolt-demo.appspot.com/#inception 但它不工作,它输出未经转换的输入json。我做错什么了吗?

    1 回复  |  直到 7 年前
        1
  •  4
  •   Milo S    7 年前

    是的,所以“shift”支持任何“regex”匹配,而不是“ $”不起作用。

    我认为最好使用“shift”匹配“foo”并将其复制到输出中。任何与“shift”规范不匹配的内容都不会复制到输出中。

    规格

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