我对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"
}
}
]
但我不能从这里继续下去。我不知道如何重命名输出中的键。
此外,删除操作的替代方法是什么?如果您要排除的键少于要包含的键,那么删除操作是好的,但反过来怎么样(包括几个键,而不是在JSON对象中排除)?
答案 0 :(得分:2)
规格
[
{
"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会复制您的数据,而其他操作则不会。因此,删除内容的一种方法就是不要在移位规范中复制它。
通常情况下,移除用于摆脱会使移位“陷入困境”的事情。