0

我有一个下面的 json,我想使用 jolt 从中提取另一个 json。使用 JOLT 转换演示网站,我可以创建一些规范,但它没有给我想要的确切 json。

{
  "status": "OK",
  "recordCount": 26,
  "startTimestamp": "2017-08-08T04:49:31.3860406Z",
  "endTimestamp": "2017-08-08T04:49:31.8860442Z",
  "timeTaken": 0.5000036,
  "apiResults": [
    {
      "sportId": 28,
      "name": "Olympics",
      "league": {
        "leagueId": 442,
        "name": "Winter Olympics",
        "abbreviation": "WNTR_OLY",
        "displayName": "Winter Olympics",
        "season": {
          "season": 2014,
          "isActive": null
        },
        "medals": [
          {
            "olympicCountry": {
              "countryId": 1000,
              "name": "Russian Federation",
              "abbreviation": "RUS"
            },
            "medalCount": {
              "gold": 13,
              "silver": 11,
              "bronze": 9,
              "total": 33
            }
          },
          {
            "olympicCountry": {
              "countryId": 8673,
              "name": "Russian Federation",
              "abbreviation": "RUS"
            },
            "medalCount": {
              "gold": 13,
              "silver": 11,
              "bronze": 9,
              "total": 33
            }
          }
        ]
      }
    }
  ]
}

我想将其转换为

{
  "data" : [
    {
    "countryCode" :  1000,
    "countryName" : "Russian Federation",
    "medals" :  {
      "gold" : 13,
      "silver" : 11,
      "bronze" : 9,
      "total" : 33
    }
    }, 
    {
      "countryCode": 8673,
      "countryName": "Russian Federation",
      "medals": {
      "gold" : 13,
      "silver" : 11,
      "bronze" : 9,
      "total" : 33
    }
    }
  ]
}

到目前为止我能弄清楚的规格是

[
  {
    "operation": "shift",
    "spec": {
      "apiResults": {
        "*": {
          "league": {
            "medals": {
              "*": {
                "olympicCountry": {
                  "countryId": "data.countryCode",
                  "name": "data.countryName"
                },
                "medalCount": "data.medals"
              }
            }
          }
        }
      }
    }
  }
]

该规范足够接近但不准确。它生成

{
  "data" : {
    "countryCode" : [ 1000, 8673 ],
    "countryName" : [ "Russian Federation", "Russian Federation" ],
    "medals" : [ {
      "gold" : 13,
      "silver" : 11,
      "bronze" : 9,
      "total" : 33
    }, {
      "gold" : 13,
      "silver" : 11,
      "bronze" : 9,
      "total" : 33
    } ]
  }
}

任何提示将不胜感激。

4

1 回答 1

0

规格

[
  {
    "operation": "shift",
    "spec": {
      "apiResults": {
        "*": {
          "league": {
            "medals": {
              "*": {
                "olympicCountry": {
                  "countryId": "data[&2].countryCode",
                  "name": "data[&2].countryName"
                },
                "medalCount": "data[&1].medals"
              }
            }
          }
        }
      }
    }
  }
]
于 2018-02-07T14:51:56.503 回答