转换JSON-JSON JOLT [英] Transform JSON-JSON JOLT

查看:415
本文介绍了转换JSON-JSON JOLT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JOLT还是很陌生,我需要将JSON文件转换为所需的架构.这是我的输入

I am quite new to JOLT and I need to transform my JSON files to the desired schema. This is my input

[
    {
        "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 
        },
        ...
    ]
}

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

So far, I have only managed up to this point:

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

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

But I can't go on from here. I don't know how to rename keys in the output.

此外,删除操作的替代方法是什么?如果要排除的键少于要包含的键,那么删除操作会很好,但是反向操作(要包含的键很少,而不是要在JSON对象中排除的键)呢?

Also, what's the alternative to remove operation? remove operation is good if you have fewer keys to exclude than to include, but how about the reverse (few keys to include, more than to exclude within a JSON object)?

推荐答案

规范

[
  {
    "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会复制您的数据,而其他操作则不会.因此,删除内容的一种方法是只是不将其复制到轮班规范中.

Shift makes copy of your data, whereas the other operations do not. Thus, one way to remove stuff is to just not have it copied across in your shift spec.

通常,remove用于消除会使"班次混乱"的事情.

Generally the remove is used to get rid of things that would "mess up" the shift.

这篇关于转换JSON-JSON JOLT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆