我有一个这样的JSON

[
  {
    "MasterUrl": "https://$$$$/exodus2022/player.aspx",
    "Programme": [
      {
        "Retirement": "2022",
        "Current Team": "Bulls",
        "Previous Team 1": "NA",
        "Previous Team 2": "NA",
        "Previous Team 3": "NA"
      },
      {
        "Retirement": "2020",
        "Current Team": "Celtics",
        "Previous Team 1": "NA",
        "Previous Team 2": "NA",
        "Previous Team 3": "NA"
      }
    ]
  },
  {
    "MasterUrl": "https://$$$$/risen2022/player.aspx",
    "Programme": [
      {
        "Current Team": "Heat",
        "Current Location": "Miami",
        "Previous Team 1": "NA",
        "Previous Team 2": "NA",
        "Previous Team 3": "NA"
      },
      {
        "Current Team": "Cavalliers",
        "Current Location": "Texas",
        "Previous Team 1": "NA",
        "Previous Team 2": "NA",
        "Previous Team 3": "NA"
      },
      {
        "Current Team": "Pistons",
        "Current Location": "New York",
        "Previous Team 1": "NA",
        "Previous Team 2": "NA",
        "Previous Team 3": "NA"
      }
    ]
  }
]

我需要将信息分成两个数组,一个用于@exodus2022 Masterurl下的数组,另一个用于@risen2022 Masterurl下的array.另外,我需要从URL和以前的团队数据中删除player.aspx.

结果应该是这样的:

[
  {
    "Exodus2022": [
      {
        "MasterUrl": "https://$$$$/exodus2022",
        "Programme": [
          {
            "Retirement": "2022",
            "Current Team": "Bulls"
          },
          {
            "Retirement": "2020",
            "Current Team": "Celtics"
          }
        ]
      }
    ]
  },
  {
    "Risen2022": [
      {
        "MasterUrl": "https://$$$$/risen2022",
        "Programme": [
          {
            "Current Team": "HEAT",
            "Current Location": "Miami"
          },
          {
            "Current Team": "Cavalliers",
            "Current Location": "Texas"
          },
          {
            "Current Team": "Pistons",
            "Current Location": "New York"
          }
        ]
      }
    ]
  }
]

这种转变能不能一蹴而就呢?

推荐答案

您可以使用以下Jolt规范:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "MasterUrl": "=split('/player.aspx', @(1,MasterUrl))",
        "MasterUr*": "=lastElement"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "key": "=split('https://\\$\\$\\$\\$/', @(1,MasterUrl))",
        "ke*": "=lastElement"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "key": "=split('', @(1,key))"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "key": {
          "[0]": "=toUpper(@(0))"
        },
        "ke*": "=join('',@0)"
      }
    }
    },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "MasterUrl|Programme": "[&1].@(1,key).&"
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "*": {
        "*": {
          "Programme": {
            "*": {
              "Previous*": ""
            }
          }
        }
      }
    }
  }
]

Json相关问答推荐

服务器不返回JSON

Jolt需要将缺少的值设置为空并保持相同的位置

有没有办法让serde_json正确/不正确地处理NaN、inf和-inf(IEEE 754特殊标准)?

(Kotlin)com.google.gson.internal.LinkedTreeMap无法转换为com.example.phonetest2.model.HallData

当由.sh脚本执行时,AWS查询字符串不会提取任何数据

使用 JOLT 将日期格式转换为 JSON

如何编写 jolt 规范以将不同的对象转换为数组

shell解析json并循环输出组合变量

使用 jq 获取特定键的所有父键

在 Perl Mojolicious 中呈现 JSON 时防止转义字符

如何使用 Serde 使用顶级数组反序列化 JSON?

在 JSON 反序列化期间没有为System.String类型定义无参数构造函数

如何从Typescript 中的json响应中获取日期对象

什么 Python 框架用于没有前端的 REST/JSON Web 服务?

直接从 Java 中的模型类创建 JSON 对象

Jsonpath 与 Jackson 或 Gson

Jackson JSON序列化,通过级别定义避免递归

Gson 将一组数据对象转换为 json - Android

如何将单引号转义成双引号转成单引号

如何遍历 JSON 中的条目?