How to use ascii characters in MuleESB Dataweave strings, £ © ¥ etc - mule

Seems like the editor is unicode aware..but the validation throws a problem
%dw 1.0
%output application/java
---
funds map {
prize_us: "\$" ++ $ as :string,
prize_uk: "£" ++ ($ * 0.81) as :string
}
Error in DW script: Invalid input """, expected typeOf, using, unaryOp, not or value
note the """ instead of the £ symbol.
Removing the £ the problem goes away and the project can compile.

Try adding the encoding also.
%dw 1.0
%input in0 application/json
%output application/java encoding="UNICODE"

Related

How do I read all of standard input in Idris2?

I'm trying to figure out how to do something very simple: read all of standard input into a string (or a list of strings would be fine too).
Prelude has getLine : HasIO io => io String, which can give me one line, but it doesn't give me a way to know that I've read it all. If there is no more input, it just gives me an empty string, which means if the input contains empty lines, I can't tell that apart from the end of the input.
Consider the following program:
module Example
main : IO ()
module Solve
main : IO ()
main = do
putStrLn ("'" ++ !getLine ++ "'")
putStrLn ("'" ++ !getLine ++ "'")
putStrLn ("'" ++ !getLine ++ "'")
putStrLn ("'" ++ !getLine ++ "'")
putStrLn ("'" ++ !getLine ++ "'")
putStrLn ("'" ++ !getLine ++ "'")
This program will print six lines, each wrapped in single quotes, taking contents from standard input. If I compile it to ./example and run with three lines of input, and a blank line in the middle, here's the output:
$ ./example <<EOF
foo
bar
EOF
'foo'
''
'bar'
''
''
''
Note that it keeps printing out lines after the standard input stream is exhausted. This means if I put this in some recursive function to get me all of the input, I don't have a reasonable stop condition.
What is the idiomatic way to read all of standard input in Idris2, without knowing at build-time how many lines of input there will be?
You can use fEOF.
You can see an example here.

Kotlin string escape special char: $

This is my scratch:
// how to present $-$ as Kotlin string
val var1 = "\$-\$"
val var2 = "\$-$"
print("${var1.count()}: $var1")
print("${var2.count()}: $var2")
print("${var1 == var2}")
can someone explain why var2 works? (no need to escape 2nd $ char?)
A template expression in a template String in Kotlin is a dollar ($) followed by either a name or an expression in curly braces (see the String templates documentation).
The single $ sign which is followed by nothing in your String var2 does not need to be escaped because it is not a template expression.

How to append --EOF to CSV file after transforming JSON to CSV in Mule 4

I want to append --EOF at the end of file in CSV after transforming JSON to CSV in Mule Data Weave 2.0
Input:
{
"serialNumber": "ABCD",
"asset": "EFGH" }
Output:
ABCD|EFGH
--EOF
Use the write() function to write the output as a string so you can concatenate it to the EOF string that you want.
Example:
%dw 2.0
output text/plain
---
write(payload, "application/csv", {"header":false, "separator" : "|"}) ++ "\n--EOF"

Dataweave2.0 in mule 4

notes=(payload.examples if payload.examples != null else “ “) ++ (\n\n**column1:\ntest: “ ++ vars.name) ++ ( “\n column2: “ ++ vars.date) ++ (“\n column3: “ ++ attributes.headers.speech)
This is DataWeave 2.0 but error said invalid input. Anyone knows how to fix this in mule 4?
As per your comment code of DataWeave 1.0. Please find the below corresponding DataWeave 2.o code.
%dw 2.0
output application/json
---
{
(payload mapObject (value, key) -> {
((key): value) if (key as String != "notes")
}),
notes:
if (payload.examples != null)
payload.examples
else
"" ++ ("\n\n**column1:\ntest: " ++ vars.name) ++ ("\n column2: " ++ vars.date) ++ ("\n column3: " ++ attributes.headers.speech)
}
the part where you are performing the condition check with if, the '=!' should be '!='.Please let me know if this has helped you.

REST API - Escaping characters

Let's assume I have a notes field with new lines characters in it.
What solution is correct and what is the difference between them?
1
{
"notes" : "test test test \n line2"
}
2
{
"notes" : "test test test \\n line2"
}
Thank you
In the output below:
{
"notes" : "test test test \n line2"
}
a new line character has been escaped using \n.
On your UI, you probably want to show
test test test
line2
I am assuming that you are retrieving the json from a data store (perhaps MySQL). If yes please see this answer about escaping newline chars in MYSSQL and MySQL string literals