0
以下是場景,我正在讀取SQL Server及其在地圖結構中讀取的數據。問題是其中一個字段是JSON字符串,但預期的輸出是JSON列表/對象。 這裏是源數據(ESB內部讀): 源數據:將json字符串轉換爲muler中的json對象
{
price_distributor=44.000000000,
width=0E-12,
tax_status=taxable,
web_ref=OLG,
stock_qty=0E-9,
price_dealer=40.000000000,
sync_uid=11,
shipping_class_id=null,
shipping_required=true,
attributes=[{"parent_sku":"BBB_BBBBB","variation":1,"attid":18,"attname":"Fabric Type","attslug":"pa_fabric-type","attuid":837,"option":"Black","termid":219,"termslug":"black","termuid":854},{"parent_sku":"AAA_AAAAA","variation":1,"attid":18,"attname":"Fabric Type","attslug":"pa_fabric-type","attuid":837,"option":"Green","termid":233,"termslug":"green","termuid":853},{"parent_sku":"YYYY_YYYYY","variation":1,"attid":18,"attname":"Fabric Type","attslug":"pa_fabric-type","attuid":837,"option":"Blue","termid":232,"termslug":"blue","termuid":848},{"parent_sku":"XXXX_XXXX","variation":1,"attid":18,"attname":"Fabric Type","attslug":"pa_fabric-type","attuid":837,"option":"Red","termid":235,"termslug":"red","termuid":851}]
}
領域中的問題是屬性和它的內容是不是一個JSON數組,而它的一個strigified陣列。
這裏是輸出:
{
"price_distributor": "44",
"width": "0",
"tax_status": "taxable",
"web_ref": "OLG",
"stock_qty": "0",
"price_dealer": "40",
"sync_uid": 11,
"shipping_class_id": null,
"shipping_required": true,
"attributes": "[{\"parent_sku\":\"BBB_BBBBB\",\"variation\":1,\"attid\":18,\"attname\":\"Fabric Type\",\"attslug\":\"pa_fabric-type\",\"attuid\":837,\"option\":\"Black\",\"termid\":219,\"termslug\":\"black\",\"termuid\":854},{\"parent_sku\":\"AAA_AAAAA\",\"variation\":1,\"attid\":18,\"attname\":\"Fabric Type\",\"attslug\":\"pa_fabric-type\",\"attuid\":837,\"option\":\"Green\",\"termid\":233,\"termslug\":\"green\",\"termuid\":853},{\"parent_sku\":\"YYYY_YYYYY\",\"variation\":1,\"attid\":18,\"attname\":\"Fabric Type\",\"attslug\":\"pa_fabric-type\",\"attuid\":837,\"option\":\"Blue\",\"termid\":232,\"termslug\"
:\"blue\",\"termuid\":848},{\"parent_sku\":\"XXXX_XXXX\",\"variation\":1,\"attid\":18,\"attname\":\"Fabric Type\",\"attslug\":\"pa_fabric-type\",\"attuid\":837,\"option\":\"Red\",\"termid\":235,\"termslug\":\"red\",\"termuid\":851}]"
}
見屬性場而打算轉型應該是:
{
"price_distributor": "44",
"width": "0",
"tax_status": "taxable",
"web_ref": "OLG",
"stock_qty": "0",
"price_dealer": "40",
"sync_uid": 11,
"shipping_class_id": null,
"shipping_required": true,
"attributes": [
{
"parent_sku":"BBB_BBBBB",
"variation":1,
"attid":18,
"attname":"Fabric Type",
"attslug":"pa_fabric-type",
"attuid":837,
"option":"Black",
"termid":219,
"termslug":"black",
"termuid":854
},
{
"parent_sku":"AAA_AAAAA",
"variation":1,
"attid":18,
"attname":"Fabric Type",
"attslug":"pa_fabric-type",
"attuid":837,
"option":"Green",
"termid":233,
"termslug":"green",
"termuid":853
},
{
"parent_sku":"YYYY_YYYYY",
"variation":1,
"attid":18,
"attname":"Fabric Type",
"attslug":"pa_fabric-type",
"attuid":837,
"option":"Blue",
"termid":232,
"termslug":"blue",
"termuid":848
},
{
"parent_sku":"XXXX_XXXX",
"variation":1,
"attid":18,
"attname":"Fabric Type",
"attslug":"pa_fabric-type",
"attuid":837,
"option":"Red",
"termid":235,
"termslug":"red",
"termuid":851
}
]
}
我用屬性的dataweave改造是這樣的:
attributes: payload.attributes
我知道這是不正確的,但有沒有一個運算符/函數可以幫助將字符串化json轉換爲json對象/列表,像json.parse()也許?
非常感謝您的幫助。
謝謝,-Sam