How to escape singlequote(') in azure logic app expression replace function
Asked Answered
E

6

5

In Azure logic Apps, how can I escape single quotes(') using a replace function?

I have a JSON payload where I have to replace a single quote(') with a double quote("). The expression I've came up with looks like this:

replace(string(@triggerBody()),'/' ','/" ')

But my second expression to escape the single quote (') isn't working.

Elwell answered 21/6, 2018 at 12:59 Comment(0)
L
6

I resolved this by using a double single quotation, '' thanks to this link

Leukemia answered 28/11, 2018 at 10:39 Comment(0)
A
3

Summary for single and doubt quotes sharing with others.

  1. String containing single quote ', use extra single quote to escape:

    ''
    
  2. String containing double quotes ", prefix with a forward slash to escape:

    \"
    
  3. Original json (posted from postman):

    {
        "name": "single''dds double\"te",
        "email": "special signle and double quotes",
        "password": "pp@pp"
    }
    
  4. console.log result in sql query in Nodejs environment:

    INSERT INTO ztestTbl(name, email, passowrd) VALUES (N'single''dds double"te', N'special signle and double quotes', N'pp@pp')
    
  5. String insert into the mssql db:

    single'dds double"te
    
Appellation answered 10/10, 2019 at 12:5 Comment(0)
L
1

Try this:

@replace(string(triggerBody()),''' ','\" ')

HTH

Lanielanier answered 22/6, 2018 at 1:56 Comment(0)
Y
1

This is now you do it. You need 2 single quotes inside the single quote

@replace(string(triggerBody()),'''' ','\" ')
Yod answered 6/10, 2020 at 13:15 Comment(0)
T
1

I had problem escaping single quote in query parameter concat. I resolved it by used double quote. Thanks to tips in this post.

concat('**Text1**', ''**'**' , '**text2**',''**'**')

resulted in :

Text1'text2'

Take a note of four single quotes.

Trig answered 22/10, 2020 at 0:33 Comment(0)
D
1

To escape a single quote in logic app expressions I was able to solve by :

@replace(variables('myString'),'''', '\''')
Damato answered 5/10, 2023 at 14:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.