Search code examples
stringmuleanypoint-studiodataweavestring-conversion

Convert string to boolean, decimal, number and integer in Dataweave


I am looking to convert the string fields from a CSV input file into specific datatypes, namely Boolean, decimal, number and integers.

When I do this in Dataweave I am receiving a message saying that dataweave cannot convert a string to e.g. integer.

This is an example of one of the conversions:

Rate: payload01."rate" as :number,

How can I do the conversions?

String -> Integer
String -> Decimal
String -> Boolean
String -> number

I'm using Anypoint Studio 6.2 and Mule 3.8.1

Thanks


Solution

  • For string to Decimal,Integer and number use: Rate: payload01."rate" as :number

    Because there is only one NUMBER type that supports both floating point and integer numbers. There is no loss of precision in any operation, the engine always stores the data in the most performant way that doesn’t compromise precision.

    For Boolean Type, you can follow this,as mentioned in Mulesoft Forum. https://forums.mulesoft.com/questions/40071/dataweave-convert-value-to-boolean-type.html

    For the errors your getting,please check the datatype of the input field "Rate".