2016-04-10 13 views
0

私はデータベースコールを持っており、以下のようにペイロードを提供しています。私はどのようにデータウェイを使用して、このペイロードをJSON形式に変換するのですか? JSONに所望mulesoft dataweaveを使用してグループ化と文字列を含むjsonに変換する方法

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 
| company |status| license_id |acct status| last_inv_date | acctnum |  owner  | entlmt |   roles   |subscribed|attr_type|  attr_key  |attr_value| 
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 
| company name 1|Active|02iq0000000xlBBAAY| Active |2016-02-25 22:50:04|A100001135|[email protected]|Standard|Admin;wcl_admin;wcl_support|  1 | cloud |cloud_num_247_t_streams|  1 | 
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 
| company name 1|Active|02iq0000000xlBBAAY| Active |2016-02-25 22:50:04|A100001135|[email protected]|Standard|Admin;wcl_admin;wcl_support|  1 | cloud |  api_access  |  1 | 
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 
| company name 1|Active|02iq0000000xlBBAAY| Active |2016-02-25 22:50:04|A100001135|[email protected]|Standard|Admin;wcl_admin;wcl_support|  1 | cloud |cloud_num_247_p_streams|  1 | 
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 
| company name 2|Active|02iq0000000xlBBBBZ| Active |2016-02-25 22:50:04|A100001166|[email protected]|Standard|   Admin   |  1 | cloud |cloud_num_247_p_streams|  0 | 
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 
| company name 2|Active|02iq0000000xlBBBBZ| Active |2016-02-25 22:50:04|A100001166|[email protected]|Standard|   Admin   |  1 | cloud |  api_access  |  1 | 
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 

最終出力:ペイロードは、その後のArrayListである:

{ 
    "records": [ 
    { 
     "company": "company name 1", 
     "has_active_subscriptions": true, 
     "license_status": "Active", 
     "license_id": "02iq0000000xlBBAAY", 
     "account_status": "Prospect", 
     "last_invoice_date": "2016-02-25 22:50:04", 
     "cloud_owner_email": "[email protected]", 
     "role": [ 
     "Admin", 
     "wcl_admin", 
     "wcl_support" 
     ], 
     "account_number": "A100001135", 
     "attributes": { 
     "cloud": { 
      "api_access": 1, 
      "cloud_num_247_t_streams": 1, 
      "cloud_num_247_p_streams": 1 
     } 
     }, 
     "entitlement_plan": "Standard" 
    }, 
    { 
     "company": "company name 2", 
     "has_active_subscriptions": true, 
     "license_status": "Active", 
     "license_id": "02iq0000000xlBBBBZ", 
     "account_status": "Active", 
     "last_invoice_date": "2016-02-25 22:50:04", 
     "cloud_owner_email": "[email protected]", 
     "role": [ 
     "Admin" 
     ], 
     "account_number": "A100001166", 
     "attributes": { 
     "cloud": { 
      "cloud_num_247_p_streams": 0, 
      "api_access": 1 
     } 
     }, 
     "entitlement_plan": "Standard" 
    } 
    ] 
} 

答えて

1

dataweave成分がちょうどデータベースコンポーネントの後で、クエリの結果は、ペイロードに残っているとするとCaseInsensitiveHashMap - あなたのJSON上のレコードオブジェクトに似ています。

%dw 1.0 
 
%output application/json 
 

 
records: payload

0

あなたはあなただけのJSONに結果セットを変換したい場合はDataWeaveを必要といけない:

だから私のような何かをしようとするだろう。 これを行うには、ObjectToJsonトランスを使用できます。

+0

どのように達成できますか? –

関連する問題