我有一个数据库调用,提供有效负载,如下所述。我如何使用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|myemail@email.com|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|myemail@email.com|Standard|Admin;wcl_admin;wcl_support| 1 | cloud | api_access | 1 |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| company name 1|Active|02iq0000000xlBBAAY| Active |2016-02-25 22:50:04|A100001135|myemail@email.com|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|myblah1@email.com|Standard| Admin | 1 | cloud |cloud_num_247_p_streams| 0 |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| company name 2|Active|02iq0000000xlBBBBZ| Active |2016-02-25 22:50:04|A100001166|myblah1@email.com|Standard| Admin | 1 | cloud | api_access | 1 |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
json中所需的最终输出:
{
"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": "myemail@email.com",
"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": "myblah@email.com",
"role": [
"Admin"
],
"account_number": "A100001166",
"attributes": {
"cloud": {
"cloud_num_247_p_streams": 0,
"api_access": 1
}
},
"entitlement_plan": "Standard"
}
]
}
答案 0 :(得分:1)
假设dataweave组件就在数据库组件之后,并且查询结果仍然在有效负载上:有效负载是CaseInsensitiveHashMap的ArrayList - 类似于JSON上的记录对象。
所以我会尝试类似的事情:
%dw 1.0
%output application/json
records: payload
答案 1 :(得分:0)
如果您只想将结果集转换为JSON,则不需要DataWeave。
您可以使用ObjectToJson
转换器来执行此操作。