2017-05-30 72 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" 
      } 
      } 
     } 
     } 
    } 
    } 
] 

移,使您的數據副本,而其他業務則沒有。因此,刪除東西的一種方法就是不要將它複製到您的換檔規格中。

一般來說,刪除是用來擺脫那些會「攪亂」這種轉變的東西。