1

我需要帮助,我是 Jolt 的新手。有一个json文件:

{
  "Date": "2021-01-01",
  "Status": "New",
  "Agreements": [
    {
      "ID_agreement": "12345",
      "ID": "fffffff",
      "balance": {
        "rub": 5,
        "usd": 6,
        "eur": 7
      },
      "withdrawal": {
        "rub": 8,
        "usd": 45,
        "eur": 6
      }
    },
    {
      "ID_agreement": "6789",
      "ID": "dddddd",
      "balance": {
        "rub": 10,
        "usd": 20,
        "eur": 30
      }
    }
  ]
}

在输出中,你真的需要得到这样的东西:

{
  "type": "DATA",
  "date": "2021-01-01",
  "id_agreement": "12345",
  "id": "fffffff",
  "source": "SITE",
  "unloadDateTime": "current date if possible",
  "balance": {
    "rub": 5,
    "usd": 6,
    "eur": 7
  },
  "withdrawal": {
    "rub": 8,
    "usd": 45,
    "eur": 6
  }
},
{
  "type": "DATA",
  "date": "2021-01-01",
  "id_agreement": "6789",
  "id": "dddddd",
  "source": "SITE",
  "unloadDateTime": "current date if possible",
  "balance": {
    "rub": 10,
    "usd": 20,
    "eur": 30
}

必须添加到每个块:

  "type": "DATA",
  "date": "2021-01-01",
  "source": "SITE",
  "unloadDateTime": "current date if possible"

并删除

"Status": "New"

原始文件很大,取款/余额字段在某处,某处不在

我最初的 Jolt 规格:

[
  {
    "operation": "remove",
    "spec": {
      "Status": ""
    }
  },
  {
    "operation": "shift",
    "spec": {
      "Agreements": {
        "*": "&"
      },
      "balance": {
        "*": "&"
      }
    }
  }
 ]

用格式化程序拆解数小时没有任何结果,任务是一次性的,请帮助,亲爱的同事!

4

1 回答 1

0

首先,balance位于底部的对象是多余的。删除之后,应用#符号来提供您想要更新当前班次转换的那些固定值,例如

[
  {
    "operation": "remove",
    "spec": {
      "Status": ""
    }
  },
  {
    "operation": "shift",
    "spec": {
      "Agreements": {
        "*": {
          "#DATA": "[&1].type",
          "#2021-01-01": "[&1].date",
          "#SITE": "[&1].source",
          "#current date if possible": "[&1].unloadDateTime",
          "*": {
            "@": "[&2].&1"
          }
        }
      }
    }
  }
 ]

在此处输入图像描述

于 2022-01-31T15:50:54.537 回答