web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Replace characters in ...
Power Automate
Unanswered

Replace characters in an array

(0) ShareShare
ReportReport
Posted on by 63
Hi all, 
 
I am trying to replace characters in an array. 
 
The below is as below:
 
[
  "| What is the Employee ID of the person you want to move? | [\"4\"] |",
  "| What is the Employees Forename | [\"Test\"] |",
  "| What is the Employee's Surname | [\"Person\"] |",
  "| What is the effective date of the change? | [\"25/11/2024\"] |",
  "| Who will be the Employee's future line manager? | [\"test@domain.com\"] |"
]
 
To get the above array, we have to convert to XML and then using a Select using the below to link the questions and answers.
addProperty(item(), 'Answer', xpath(outputs('XML'), concat('//root/array[Sequence/text()="', item()['Sequence'], '"]/Answer/text()')))
 
We then use another Select action from the output of the above and use 
concat('| ',item()?['Question'],' | ',item()?['Answer'],' |')
 
We then want to use the array in an Approvals action, as below, and we are currently using 
join(body('Map_Questions_and_Answers_for_Approval'),decodeUriComponent('%0A'))
to do this.
 
 
But the output received by the Approver still has [" and "] around each Response. How can we remove these in the easiest way?   Converting to a string, using replace() and then back into an array is really complicated, as we have to use XML to get the array in the first place.
 
Many thanks, 
SD.
 
 
Categories:
I have the same question (0)
  • Expiscornovus Profile Picture
    33,175 Most Valuable Professional on at
    Replace characters in an array
     
    You can use a json and a join to convert the string array to a value.
     
    Below is an example
     
    Question key
    split(item(), '|')[1]
    Response key
     
    join(json(split(item(), '|')[2]), '')
     
     
    Test result
     
  • sausage_dog Profile Picture
    63 on at
    Replace characters in an array
    @Expiscornovus - Thanks. However, in the Approval action, we can't use HTML... it has to be Markdown... :(
  • Expiscornovus Profile Picture
    33,175 Most Valuable Professional on at
    Replace characters in an array
     
    The Create HTML table was just to show that it is an array without the special characters. You can ignore that Create HTML table action, you don't have to use that. The suggested approach is in the Select action.
     
    I have updated my example to your situation (with the markdown), if that helps?
     
    1. Second select uses the same name and concat function in the map field
    concat('| ',item()?['Question'],' | ',item()?['Answer'],' |')
    2. Compose action to create the markdown table
    | Question | Response |
    |-----------|:-----------:|
    @{join(body('Map_Questions_and_Answers_for_Approval'),decodeUriComponent('%0A'))}
     
     
     
    Test result
     
  • Chriddle Profile Picture
    8,416 Super User 2025 Season 2 on at
    Replace characters in an array
    The text() in the xpath returns an array. Hence the brackets.
    Simply take the first value from this array:
    addProperty(
    	item(),
    	'Answer', 
    	first(
    		xpath(
    			outputs('XML'),
    			concat('//root/array[Sequence/text()="', item()['Sequence'], '"]/Answer/text()')
    		)
    	)
    )
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 497 Moderator

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 477 Super User 2025 Season 2

#3
chiaraalina Profile Picture

chiaraalina 242

Last 30 days Overall leaderboard