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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to Replace Values ...
Power Automate
Answered

How to Replace Values JSON

(0) ShareShare
ReportReport
Posted on by
Hi,
 
Just some background, I have converted a CSV file to Json - I'm under the impression you cannot edit CSV files within power automate.
 
I now have an array that looks like this...
 
[
  {
    "Serial Number""850375895",
    "Black Toner""Low",
    "Cyan Toner""41%",
    "Magenta Toner""7%",
    "Yellow Toner""39%",
    "Last Reported""7/29/2021 9:35 AM\r"
  },
  {
    "Serial Number""951309875",
    "Black Toner""Low",
    "Cyan Toner""75%",
    "Magenta Toner""74%",
    "Yellow Toner""81%",
    "Last Reported""11/01/2021 16:34\r"
  },
 
I want to replace the low values with 5%, please can you help?
 
Updated flow with solution:
garethaw_0-1635936831594.png

 

Categories:
I have the same question (0)
  • Verified answer
    MarvinBangert Profile Picture
    1,924 Most Valuable Professional on at

    Hey @Anonymous 

    you could use the "Select" action to update the content within your array and create a new array to go on. I just copied your code piece into an variable, parse the JSON (just use the "Generate from sample" and add your code there). The parsing helps me to select the items, within the value I just use the replace() expression to change the text:

    replace(item()?['Black Toner'],'Low','5%')

     

    Image 719.png

     

    Best regards
    Marvin

    If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

  • Community Power Platform Member Profile Picture
    on at

    Hi Marvin,

     

    Thanks for your help, is there a way I can replace multiple values, for example if the "Black Toner" is "High" replace with "100%".

     

    [
      {
        "Serial Number""850375895",
        "Black Toner""Low",
        "Cyan Toner""41%",
        "Magenta Toner""7%",
        "Yellow Toner""39%",
        "Last Reported""7/29/2021 9:35 AM\r"
      },
      {
        "Serial Number""951309875",
        "Black Toner""High",
        "Cyan Toner""75%",
        "Magenta Toner""74%",
        "Yellow Toner""81%",
        "Last Reported""11/01/2021 16:34\r"
      },
  • MarvinBangert Profile Picture
    1,924 Most Valuable Professional on at

    Hey @Anonymous 

    you can just combine multiple replace() expressions:

    replace(replace(item()?['Black Toner'],'Low','5%'),'High','100%')

     

    Best regards
    Marvin

    If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

  • eliotcole Profile Picture
    4,363 Moderator on at

     You can also use the setProperty() function in an expression, @Anonymous . Plus, you will need to put an if() function in there, too.

     

    We really need to see your flow, mate. 😉 

     

     I'm not at a computer right now, but however you're creating the json I would recommend doing it on that actual step, so you can then just wrap this around it. However it would be ideal to see your flow so that we can better assist.

     

     Could you post screenshots? Just black  out sensitive data.

     

     here's a basic setProperty():

     

    setProperty(data, 'Black Toner', '100%')

     

     Use that with an if statement ... .  hang on I'll just get to a computer.

     

     in the meantime can you post your flow? (edited in to the original post is best)

  • Community Power Platform Member Profile Picture
    on at

    That's worked, appreciate I'm a bit off topic here but how would I now convert the json back to csv?

     

    Here is the original CSV:

    garethaw_0-1635937081677.png

     

     

     

  • MarvinBangert Profile Picture
    1,924 Most Valuable Professional on at

    Hey @eliotcole 

    doesn't the setProperty only runs on objects, not on arrays? So you would also need an "Apply to each" and a more complex formula to check for the wright input and afterwards adding the object back into an array variable. Also the "Apply to each" takes usually more time to complete.

     

    Yes, there are multiple ways to achieve this, but i guess using the "Select" with a replace is the most time efficient and easiest in this case.

     

    Best regards
    Marvin

    If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

    Blog: Cloudkumpel

  • Community Power Platform Member Profile Picture
    on at

    Posted my flow, the replace query works. To take it 1 step further how difficult would it be to replace any value between 75%-90% to 91%.

     

    For example If Black Toner = 77% replace with 91%

     

    Anyway of doing this without having 15+ replace expressions.

  • MarvinBangert Profile Picture
    1,924 Most Valuable Professional on at

    Hey @Anonymous 

    there is an action called "Create CSV table" within the "Data operation" actions. The "From" is your "Select" Output. Within the "Show advanced options" you can choose if you want to create the columns automatically or manually.

     

    Best regards
    Marvin

    If you like this post, give a Thumbs up. If it solved your request, Mark it as a Solution to enable other users to find it.

    Blog: Cloudkumpel

  • Community Power Platform Member Profile Picture
    on at

    Hi Marvin,

     

    That seems to work okay but the resulting csv has quotations? 

     

    garethaw_0-1635942916980.png

     

  • MarvinBangert Profile Picture
    1,924 Most Valuable Professional on at

    Hey @Anonymous 

    can you please show the flow with the select, create CSV table and create file action?

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
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard