2017-03-20 13 views
1

jsonの要素をマスクしたい。下のjsonのdescID要素はマスクする必要があります。あなたはお勧めしますか?dataweaveを使用して複雑なjson構造の値をマスクする方法はありますか?

{ 
    "status": "ok", 
    "statusCode": "19x9s011", 
    "statusDescription": "Service: XYZ IOP ; country: india ; Locale:en-US ; SourceId:KOP; ApiUid: 644e1dd7-2a7f-18fb-b8ed-ed78c3f899s2c2b; Description: The NMK profile call was successful.", 
    "details": { 
     "descID": "11840000000012698", 
     "Code": "XX", 
     "languageCode": "en", 
     "profile": { 
      "base": { 
       "username": "abc", 
       "firstName": "xc", 
       "middleName": "test", 
       "lastName": "123", 
       "shortName": "xc", 
       "displayName": "D", 
       "suffix": "T", 
       "prefix": "E" 
      } 
     } 
    } 
} 

答えて

1

私はデータをマスクするようなものを使用することがあります:

%dw 1.0 
%input payload application/json 
%output application/json 


%var keyToEncrypt = ['descID'] 

%function encrypt(val) "*****" 

%function needsEncrypt(key) (sizeOf (keyToEncrypt find key)) > 0 


%function maskSensitiveData(value) value mapObject ({ 
($$) : maskSensitiveData($) when $ is :object otherwise $ 
} unless needsEncrypt($$ as :string) otherwise { 
($$) : encrypt($) 
}) 

--- 

maskSensitiveData(payload) 

これは、あなたが完全にフィールドを削除する必要がある場合は、その後、私のようなものを使用する場合がありますhttps://blogs.mulesoft.com/dev/training-dev/encrypt-specific-xml-tags-with-the-power-of-dataweave/

を丸写ししたものです。

%dw 1.0 
%input payload application/json 
%output application/json 


%var keyToEncrypt = ['descID'] 

%function encrypt(val) "*****" 

%function needsEncrypt(key) (sizeOf (keyToEncrypt find key)) > 0 


%function maskSensitiveData(value) value mapObject ({ 
($$) : maskSensitiveData($) when $ is :object otherwise $ 
} unless needsEncrypt($$ as :string) otherwise {}) 

--- 

maskSensitiveData(payload) 
+0

こんにちはチャド、応答ありがとうございます。私の要件は出力descID要素にあります。それがステータスコードのような最初のレベルに直接あるなら、私はそれをpaylaod - stausのようにすることができます。削除する要素が複数のレベルの下にある場合、これをどのように正確に処理するのでしょうか? – Sushma

+0

@Sushma私は自分の答えを更新しました。 –

関連する問題