在将有效负载转换为mule中的json时无法获得正确的数组结构

时间:2016-10-28 18:23:49

标签: json mule mule-component dataweave x12

我将x12 837文件作为输入并将其转换为java然后转换为json。下面是我在dataweave中的代码

%dw 1.0
%output application/json
---
payload.*"2000_Loop" map {
    Claims: $.*"2300_Loop" map {
        claimnumber: $."1300_CLM".CLM01,
        monetoryamount: $."1300_CLM".CLM02
    } 
}

当我写上面的代码时,我得到如下输出:

[
  {
    "Claims": [
      {
        "claimnumber": [
          "945405", "234512"
        ],
        "monetoryamount": [
          5332.54, 876
        ]
      }
    ]
  }
]

预期输出为:

[
  {
    "Claims": [
      {
        "claimnumber": "945405",
        "monetoryamount": 5332.54
      }
    ],
    "Claims": [
      {
        "claimnumber": "234512",
        "monetoryamount": 876
      }
    ]
  }
]

我的输入文件是x12"我已经转换为java传递给上面的dataweave组件:

ISA*00*          *00*          *ZZ*SENDER         *ZZ*RECEIVER       *111219*1340*^*00501*000001377*0*T*>
GS*HC*SENDER*RECEIVER*20111219*1340*1377*X*005010X222
ST*837*0001*005010X222
BHT*0019*00*565743*20110523*154959*CH
NM1*41*2*SAMPLE INC*****46*496103
PER*IC*EDI DEPT*EM*FEEDBACK@1EDISOURCE.COM*TE*3305551212
NM1*40*2*PPO BLUE*****46*54771
HL*1**20*1
PRV*BI*PXC*333600000X
NM1*85*2*EDI SPECIALTY SAMPLE*****XX*123456789
N3*1212 DEPOT DRIVE
N4*CHICAGO*IL*606930159
REF*EI*300123456
HL*2*1*22*1
SBR*P********BL
NM1*IL*1*CUSTOMER*KAREN****MI*YYX123456789
N3*228 PINEAPPLE CIRCLE
N4*CORA*PA*15108
DMG*D8*19630625*M
NM1*PR*2*PPO BLUE*****PI*54771
N3*PO BOX 12345
N4*CAMP HILL*PA*17089
HL*3*2*23*0
PAT*19
NM1*QC*1*CUSTOMER*COLE
N3*228 PINEAPPLE CIRCLE
N4*CORA*PA*15108
DMG*D8*19940921*M
CLM*945405*5332.54***12>B>1*Y*A*Y*Y*P
HI*BK>2533
LX*1
SV1*HC>J2941*5332.54*UN*84***1
DTP*472*RD8*20110511-20110511
REF*6R*1099999731
NTE*ADD*GENERIC 12MG CARTRIDGE
LIN**N4*00013264681
CTP****7*UN
NM1*DK*1*PATIENT*DEBORAH****XX*12345679030
N3*123 MAIN ST*APT B
N4*PITTSBURGH*PA*152181871
CLM*234512*876***12>B>1*Y*A*Y*Y*P
HI*BK>2533
LX*1
SV1*HC>J2941*5332.54*UN*84***1
DTP*472*RD8*20110511-20110511
REF*6R*1099999731
NTE*ADD*GENERIC 12MG CARTRIDGE
LIN**N4*00013264681
CTP****7*UN
NM1*DK*1*PATIENT*DEBORAH****XX*12345679030
N3*123 MAIN ST*APT B
N4*PITTSBURGH*PA*152181871
SE*63*0001
GE*1*1377
IEA*1*000001377
%dw 1.0
%output application/json

payload.*"2000_Loop" map {
  Claims: $.*"2300_Loop" map {
    Claim: $."1300_CLM" map {
      claimnumber: $.CLM01,
      monetoryamount: $.CLM02
    }
  }
}

1 个答案:

答案 0 :(得分:0)

您是否尝试过以下表达式?

%dw 1.0
%output application/json
---
payload.*"2000_Loop" map {
    Claims: $.*"2300_Loop".*"1300_CLM" map {
        claimnumber: $.CLM01,
        monetoryamount: $.CLM02
    } 
}