您好我正在使用Mulesoft 3.8.4中的Dataweave將JSON轉換爲JSON。我正在與在JSON以下行(較大文件的一部分)使用DataWeave在JSON中檢查空和缺少的字段值
..
"someField": "12",
"otherField": "5441",
..
我想格式化工作「someField」到零左填充字符串的4(0012)的總長度。我也想把這個值連接到另一個也需要填充的字段,但總長度爲6. 爲了防止填充和連接失敗,我必須檢查字段是否存在,而不是空的,它必須是數字。
我有以下代碼:
"My Number": someField as :number as :string {format: "0000"} ++ otherField as :number as :string {format: "0000"}
when somefield != null
and someField != ""
and someField is :number
and otherField != null
and otherField != ""
and otherField is :number
otherwise "",
但這種失敗,因爲「是:數」,因爲實際值是一個字符串,返回false。當值爲空時,檢查'and someField as:number is:number'等內容也會失敗。什麼是最好的檢查方法?
Thanx幫助。
約翰