转换 JSON-JSON JOLT
Transform JSON-JSON JOLT
我对 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 对象中排除)?
规格
[
{
"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 会复制您的数据,而其他操作则不会。因此,删除内容的一种方法是不要将其复制到您的班次规范中。
通常,删除用于删除会 "mess up" 转移的内容。
我对 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 对象中排除)?
规格
[
{
"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 会复制您的数据,而其他操作则不会。因此,删除内容的一种方法是不要将其复制到您的班次规范中。
通常,删除用于删除会 "mess up" 转移的内容。