2016-04-10 4 views
0

Ich habe einen Datenbankaufruf, der eine Payload wie unten beschrieben bereitstellt. Wie verwende ich DataWeave, um diese Nutzlast in json in dem Format umzuwandeln, wie es unter der Beispieltabelle angegeben ist?wie man mulesoft dataweave verwendet, um nach json mit Gruppierung und String in Array zu transformieren

|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 
| 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 | 
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 

fertige Ausgabe in json gewünscht:

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

Antwort

1

Annahme, dass die dataweave Komponente unmittelbar nach der Datenbankkomponente ist, und das Ergebnis der Abfrage ist immer noch auf der Nutzlast: ist die Nutzlast dann eine Arraylist von CaseInsensitiveHashMap - ähnlich dem Datensatzobjekt in Ihrem JSON.

So würde ich versuchen, so etwas wie:

%dw 1.0 
 
%output application/json 
 

 
records: payload

0

Sie nicht DataWeave benötigen, wenn Sie nur resultset in JSON umwandeln möchten. Sie können dazu ObjectToJson Transformator verwenden.

+0

Wie kann das erreicht werden? –

Verwandte Themen