Jolt 变换未命名数组

Jolt transform unnamed array

使用来自 jsonplaceholder.com 的示例 json 响应,我想对返回的未命名数组执行 Jolt 转换。

但是,使用 jolt demo 我只能在命名数组(本例中为 "records")并用花括号括起来后转换数组。像这样:

Json 输入:

{
"records": [
    {
        "id": 1,
        "name": "Leanne Graham",
        "username": "Bret",
        "email": "Sincere@april.biz",
        "address": {
            "street": "Kulas Light",
            "suite": "Apt. 556",
            "city": "Gwenborough",
            "zipcode": "92998-3874",
            "geo": {
                "lat": "-37.3159",
                "lng": "81.1496"
            }
        },
        "phone": "1-770-736-8031 x56442",
        "website": "hildegard.org",
        "company": {
            "name": "Romaguera-Crona",
            "catchPhrase": "Multi-layered client-server neural-net",
            "bs": "harness real-time e-markets"
        }
    },
    {
        "id": 2,
        "name": "Ervin Howell",
        "username": "Antonette",
        "email": "Shanna@melissa.tv",
        "address": {
            "street": "Victor Plains",
            "suite": "Suite 879",
            "city": "Wisokyburgh",
            "zipcode": "90566-7771",
            "geo": {
                "lat": "-43.9509",
                "lng": "-34.4618"
            }
        },
        "phone": "010-692-6593 x09125",
        "website": "anastasia.net",
        "company": {
            "name": "Deckow-Crist",
            "catchPhrase": "Proactive didactic contingency",
            "bs": "synergize scalable supply-chains"
        }
    }
  ]
}

颠簸规格:

[ { "operation": "shift", "spec": { "records": { "*": { "id": "records[&1].user-id", "username": "records[&1].user-username", "email": "records[&1].user-email", "address": { "street": "records[&2].user-street", "suite": "records[&2].user-suite", "city": "records[&2].user-city", "zipcode": "records[&2].user-zipcode" } } } } } ]

我的示例的目标是展平响应中返回的对象层次结构,同时保持基本的 [{}, {}, ...] 结构。

当输入是一个未命名的 json 数组时,如何实现这一点?

发帖后才知道答案...

这是我为任何感兴趣的人修改的规范:

[ { "operation": "shift", "spec": { "*": { "id": "[&1].user-id", "username": "[&1].user-username", "email": "[&1].user-email", "address": { "street": "[&2].user-street", "suite": "[&2].user-suite", "city": "[&2].user-city", "zipcode": "[&2].user-zipcode" } } } } ]

声明spec("spec": { "*": { ")后简单匹配,然后用[&1][&2]等访问无名数组

下面一个有效,但没有变平

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "id": "[&1].user-id",
          "username": "[&1].user-username",
          "email": "[&1].user-email",
          "address": {
            "street": "[&2].user-street",
            "suite": "[&2].user-suite",
            "city": "[&2].user-city",
            "zipcode": "[&2].user-zipcode"
          }
        }
      }
    }
  }
]