Jolt - 递归过程

Jolt - recurcive process

我尝试使用 Jolt 展平一些 JSON 数组。我在第一级找到了如何做,但我需要做 "recursively".

关于输入:

这是一个简单的示例:

{
    "objects": [
        {
            "name": "first",
            "type": "FIRST",
            "1st_attr": 0
        },
        {
            "name": "second",
            "type": "SECOND",
            "2nd_attr": 0
        }
    ],
    "sub": {
        "objects": [
            {
                "name": "third",
                "type": "THIRD",
                "3rd_attr": 0
            }
        ]
    }
}

这是我想要的输出:

{
  "first" : {
    "1st_attr" : 0,
    "name" : "first",
    "type" : "FIRST"
  },
  "second" : {
    "2nd_attr" : 0,
    "name" : "second",
    "type" : "SECOND"
  },
  "sub" : {
    "third" : {
      "3rd_attr" : 0,
      "name" : "third",
      "type" : "THIRD"
    }
  }
}

规范我已将第一层展平,但我希望它展平每一层(意思是,不仅仅是第二层 ;)...):

[
  {
    "operation": "shift",
    "spec": {
      "objects": {
        "*": {
          "@": "@(1,name)"
        }
      },
      "*": "&0"
    }
  }
]

感谢您的帮助

使用 Jolt,您必须知道 "object" 数组在输入中的位置。没有办法 "just find and flatten all the arrays, no matter where they are in the input doc".

您提供的输入和输出规范:

[
  {
    "operation": "shift",
    "spec": {
      "objects": {
        "*": "@(0,name)"
      },
      "sub": {
        "objects": {
          "*": "&2.@(0,name)"
        }
      }
    }
  }
]

编辑:添加 &2. 以具有 sub.third 而不仅仅是 third