2017-05-30 154 views
0

我是JOLT的新手,我需要将我的JSON文件转换为所需的模式。这是我的输入转换JSON-JSON JOLT

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

,这是我想要的输出:

{ 
    "records": [ 
     { 
      "attribs": [{ 
       "type": "customer", 
       "reference": "CUST" 
      }], 
      "name": "Amit Prakash", 
      "personal_email": "[email protected]", 
      "mobile": "809386731", 
      "id": 12345 
     }, 
     { 
      "attribs": [{ 
       "type": "customer", 
       "reference": "CUST" 
      }], 
      "name": "Rohit Dhand", 
      "personal_email": "[email protected]", 
      "mobile": "937013861", 
      "id": 12654 
     }, 
     ... 
    ] 
} 

到目前为止,我只设法到这一点:

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

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

另外,有什么可以替代删除操作? 删除如果您排除的键数少于包含的键,那么操作是很好的,但反过来如何(包含几个键,多于在JSON对象内排除)?

回答

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" 
      } 
      } 
     } 
     } 
    } 
    } 
] 

移,使您的数据副本,而其他业务则没有。因此,删除东西的一种方法就是不要将它复制到您的换档规格中。

一般来说,删除是用来摆脱那些会“搅乱”这种转变的东西。