【问题标题】:Transform JSON-JSON JOLT转换 JSON-JSON JOLT
【发布时间】:2017-05-30 12:33:57
【问题描述】:

我对 JOLT 很陌生,我需要将我的 JSON 文件转换为所需的架构。这是我的意见

[
    {
        "PK": 12345,
        "FULL_NAME":"Amit Prakash",
        "BIRTHDATE":"1987-05-25",
        "SEX":"M",
        "EMAIL": "amprak@mail.com",
        "PHONE": "809386731",
        "TS":"2015-11-19 14:36:34.0"
    },
    {
        "PK": 12654,
        "FULL_NAME": "Rohit Dhand",
        "BIRTHDATE":"1979-02-01",
        "SEX":"M",
        "EMAIL": "rodha@mail.com",
        "PHONE": "937013861",
        "TS":"2015-11-20 11:03:02.6"
    },
    ...
]

这是我想要的输出:

{
    "records": [
        {
            "attribs": [{
                "type": "customer",
                "reference": "CUST"
            }],
            "name": "Amit Prakash",
            "personal_email": "amprak@mail.com",
            "mobile": "809386731",
            "id": 12345 
        },
        {
            "attribs": [{
                "type": "customer",
                "reference": "CUST"
            }],
            "name": "Rohit Dhand",
            "personal_email": "rodha@mail.com",
            "mobile": "937013861",
            "id": 12654 
        },
        ...
    ]
}

到目前为止,我只做到了这一点:

[
  {
    "operation": "remove",
    "spec": {
      "*": {
        "BIRTHDATE": "",
        "SEX": "",
        "TS": ""
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": "records"
    }
  }
]

但我不能从这里继续下去。我不知道如何重命名输出中的键。

另外,remove 操作的替代方法是什么?如果要排除的键比要包含的键少,删除 操作很好,但反过来呢(要包含的键少,而不是 JSON 对象中要排除的键多)?

【问题讨论】:

    标签: json jolt


    【解决方案1】:

    规格

    [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "PK": "records[&1].id",
            "PHONE": "records[&1].mobile",
            "EMAIL": "records[&1].personal_email",
            "FULL_NAME": "records[&1].name"
          }
        }
      },
      {
        "operation": "default",
        "spec": {
          "records[]": {
            "*": {
              "attribs[]": {
                "0": {
                  "type": "customer",
                  "reference": "CUST"
                }
              }
            }
          }
        }
      }
    ]
    

    Shift 会复制您的数据,而其他操作则不会。因此,删除内容的一种方法是不要将其复制到您的班次规范中。

    通常,remove 用于消除会“扰乱”班次的事情。

    【讨论】:

      猜你喜欢
      • 2021-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-02
      • 2020-11-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多