cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
hongdet
Helper III
Helper III

List to match and return value

Hi Power Automate Community, 

 

I've a JSON list as follows and wish to use the string in there for matching:

 

{
  "Pacific/Midway": "(UTC-11:00) Midway Island, Samoa",
  "Pacific/Pago_Pago": "(UTC-11:00) Pago Pago",
  "Pacific/Honolulu": "(UTC-10:00) Hawaii",
  "America/Anchorage": "(UTC-8:00) Alaska",
  "America/Juneau": "(UTC-8:00) Juneau",
  "America/Vancouver": "(UTC-7:00) Vancouver",
  "America/Los_Angeles": "(UTC-7:00) Pacific Time (US and Canada)",
  "America/Tijuana": "(UTC-7:00) Tijuana",
  "America/Phoenix": "(UTC-7:00) Arizona",
  "America/Edmonton": "(UTC-6:00) Edmonton",
  "America/Denver": "(UTC-6:00) Mountain Time (US and Canada)",
  "America/Mazatlan": "(UTC-6:00) Mazatlan",
  "America/Regina": "(UTC-6:00) Saskatchewan",
  "America/Guatemala": "(UTC-6:00) Guatemala",
  "America/El_Salvador": "(UTC-6:00) El Salvador",
  "America/Managua": "(UTC-6:00) Managua",
  "America/Costa_Rica": "(UTC-6:00) Costa Rica",
  "America/Tegucigalpa": "(UTC-6:00) Tegucigalpa",
  "America/Chihuahua": "(UTC-6:00) Chihuahua",
  "America/Winnipeg": "(UTC-5:00) Winnipeg",
  "America/Chicago": "(UTC-5:00) Central Time (US and Canada)",
  "America/Mexico_City": "(UTC-5:00) Mexico City",
  "America/Panama": "(UTC-5:00) Panama",
  "America/Bogota": "(UTC-5:00) Bogota",
  "America/Lima": "(UTC-5:00) Lima",
  "America/Monterrey": "(UTC-5:00) Monterrey",
  "America/Montreal": "(UTC-4:00) Montreal",
  "America/New_York": "(UTC-4:00) Eastern Time (US and Canada)",
  "America/Indianapolis": "(UTC-4:00) Indiana (East)",
  "America/Puerto_Rico": "(UTC-4:00) Puerto Rico",
  "America/Caracas": "(UTC-4:00) Caracas",
  "America/Santiago": "(UTC-4:00) Santiago",
  "America/La_Paz": "(UTC-4:00) La Paz",
  "America/Guyana": "(UTC-4:00) Guyana",
  "America/Halifax": "(UTC-3:00) Halifax",
  "America/Montevideo": "(UTC-3:00) Montevideo",
  "America/Araguaina": "(UTC-3:00) Recife",
  "America/Argentina/Buenos_Aires": "(UTC-3:00) Buenos Aires, Georgetown",
  "America/Sao_Paulo": "(UTC-3:00) Sao Paulo",
  "Canada/Atlantic": "(UTC-3:00) Atlantic Time (Canada)",
  "America/St_Johns": "(UTC-2:30) Newfoundland and Labrador",
  "America/Godthab": "(UTC-2:00) Greenland",
  "Atlantic/Cape_Verde": "(UTC-1:00) Cape Verde Islands",
  "Atlantic/Azores": "(UTC+0:00) Azores",
  "UTC": "(UTC+0:00) Universal Time UTC",
  "Etc/Greenwich": "(UTC+0:00) Greenwich Mean Time",
  "Atlantic/Reykjavik": "(UTC+0:00) Reykjavik",
  "Africa/Casablanca": "(UTC+0:00) Casablanca",
  "Africa/Nouakchott": "(UTC+0:00) Nouakchott",
  "Europe/Dublin": "(UTC+1:00) Dublin",
  "Europe/London": "(UTC+1:00) London",
  "Europe/Lisbon": "(UTC+1:00) Lisbon",
  "Africa/Bangui": "(UTC+1:00) West Central Africa",
  "Africa/Algiers": "(UTC+1:00) Algiers",
  "Africa/Tunis": "(UTC+1:00) Tunis",
  "Europe/Belgrade": "(UTC+2:00) Belgrade, Bratislava, Ljubljana",
  "CET": "(UTC+2:00) Sarajevo, Skopje, Zagreb",
  "Europe/Oslo": "(UTC+2:00) Oslo",
  "Europe/Copenhagen": "(UTC+2:00) Copenhagen",
  "Europe/Brussels": "(UTC+2:00) Brussels",
  "Europe/Berlin": "(UTC+2:00) Amsterdam, Berlin, Rome, Stockholm, Vienna",
  "Europe/Amsterdam": "(UTC+2:00) Amsterdam",
  "Europe/Rome": "(UTC+2:00) Rome",
  "Europe/Stockholm": "(UTC+2:00) Stockholm",
  "Europe/Vienna": "(UTC+2:00) Vienna",
  "Europe/Luxembourg": "(UTC+2:00) Luxembourg",
  "Europe/Paris": "(UTC+2:00) Paris",
  "Europe/Zurich": "(UTC+2:00) Zurich",
  "Europe/Madrid": "(UTC+2:00) Madrid",
  "Africa/Harare": "(UTC+2:00) Harare, Pretoria",
  "Europe/Warsaw": "(UTC+2:00) Warsaw",
  "Europe/Prague": "(UTC+2:00) Prague Bratislava",
  "Europe/Budapest": "(UTC+2:00) Budapest",
  "Africa/Tripoli": "(UTC+2:00) Tripoli",
  "Africa/Cairo": "(UTC+2:00) Cairo",
  "Africa/Johannesburg": "(UTC+2:00) Johannesburg",
  "Africa/Khartoum": "(UTC+2:00) Khartoum",
  "Europe/Helsinki": "(UTC+3:00) Helsinki",
  "Africa/Nairobi": "(UTC+3:00) Nairobi",
  "Europe/Sofia": "(UTC+3:00) Sofia",
  "Europe/Istanbul": "(UTC+3:00) Istanbul",
  "Europe/Athens": "(UTC+3:00) Athens",
  "Europe/Bucharest": "(UTC+3:00) Bucharest",
  "Asia/Nicosia": "(UTC+3:00) Nicosia",
  "Asia/Beirut": "(UTC+3:00) Beirut",
  "Asia/Damascus": "(UTC+3:00) Damascus",
  "Asia/Jerusalem": "(UTC+3:00) Jerusalem",
  "Asia/Amman": "(UTC+3:00) Amman",
  "Europe/Moscow": "(UTC+3:00) Moscow",
  "Asia/Baghdad": "(UTC+3:00) Baghdad",
  "Asia/Kuwait": "(UTC+3:00) Kuwait",
  "Asia/Riyadh": "(UTC+3:00) Riyadh",
  "Asia/Bahrain": "(UTC+3:00) Bahrain",
  "Asia/Qatar": "(UTC+3:00) Qatar",
  "Asia/Aden": "(UTC+3:00) Aden",
  "Africa/Djibouti": "(UTC+3:00) Djibouti",
  "Africa/Mogadishu": "(UTC+3:00) Mogadishu",
  "Europe/Kiev": "(UTC+3:00) Kiev",
  "Europe/Minsk": "(UTC+3:00) Minsk",
  "Asia/Dubai": "(UTC+4:00) Dubai",
  "Asia/Muscat": "(UTC+4:00) Muscat",
  "Asia/Baku": "(UTC+4:00) Baku, Tbilisi, Yerevan",
  "Asia/Tehran": "(UTC+4:30) Tehran",
  "Asia/Kabul": "(UTC+4:30) Kabul",
  "Asia/Yekaterinburg": "(UTC+5:00) Yekaterinburg",
  "Asia/Tashkent": "(UTC+5:00) Islamabad, Karachi, Tashkent",
  "Asia/Calcutta": "(UTC+5:30) India",
  "Asia/Kolkata": "(UTC+5:30) Mumbai, Kolkata, New Delhi",
  "Asia/Colombo": "(UTC+5:30) Asia/Colombo",
  "Asia/Kathmandu": "(UTC+5:45) Kathmandu",
  "Asia/Almaty": "(UTC+6:00) Almaty",
  "Asia/Dacca": "(UTC+6:00) Dacca",
  "Asia/Dhaka": "(UTC+6:00) Astana, Dhaka",
  "Asia/Rangoon": "(UTC+6:30) Rangoon",
  "Asia/Novosibirsk": "(UTC+7:00) Novosibirsk",
  "Asia/Krasnoyarsk": "(UTC+7:00) Krasnoyarsk",
  "Asia/Bangkok": "(UTC+7:00) Bangkok",
  "Asia/Saigon": "(UTC+7:00) Vietnam",
  "Asia/Jakarta": "(UTC+7:00) Jakarta",
  "Asia/Irkutsk": "(UTC+8:00) Irkutsk, Ulaanbaatar",
  "Asia/Shanghai": "(UTC+8:00) Beijing, Shanghai",
  "Asia/Hong_Kong": "(UTC+8:00) Hong Kong SAR",
  "Asia/Taipei": "(UTC+8:00) Taipei",
  "Asia/Kuala_Lumpur": "(UTC+8:00) Kuala Lumpur",
  "Asia/Singapore": "(UTC+8:00) Singapore",
  "Australia/Perth": "(UTC+8:00) Perth",
  "Asia/Yakutsk": "(UTC+9:00) Yakutsk",
  "Asia/Seoul": "(UTC+9:00) Seoul",
  "Asia/Tokyo": "(UTC+9:00) Osaka, Sapporo, Tokyo",
  "Australia/Darwin": "(UTC+9:30) Darwin",
  "Australia/Adelaide": "(UTC+9:30) Adelaide",
  "Asia/Vladivostok": "(UTC+10:00) Vladivostok",
  "Pacific/Port_Moresby": "(UTC+10:00) Guam, Port Moresby",
  "Australia/Brisbane": "(UTC+10:00) Brisbane",
  "Australia/Sydney": "(UTC+10:00) Canberra, Melbourne, Sydney",
  "Australia/Hobart": "(UTC+10:00) Hobart",
  "Asia/Magadan": "(UTC+11:00) Magadan",
  "SST": "(UTC+11:00) Solomon Islands",
  "Pacific/Noumea": "(UTC+11:00) New Caledonia",
  "Asia/Kamchatka": "(UTC+12:00) Kamchatka",
  "Pacific/Fiji": "(UTC+12:00) Fiji Islands, Marshall Islands",
  "Pacific/Auckland": "(UTC+12:00) Auckland, Wellington",
  "Pacific/Apia": "(UTC+13:00) Independent State of Samoa"
}

 

 

What I'm trying to achieve here is that the user would provide this string, 

 

(UTC-11:00) Midway Island, Samoa

 

and I would like have it match and returned me the following string,

 

Pacific/Midway

 

 

Seeking all the kind assistance avaliable here! Thanks in advance! 

1 ACCEPTED SOLUTION

Accepted Solutions
grantjenkins
Super User
Super User

It's difficult to get the actual property name by searching on the value when using JSON. In this instance I would convert your JSON to XML then use XPath to get what we want.

 

See full flow below. I'll go into each of the actions.

grantjenkins_0-1672845898865.png

 

Criteria is a Compose that contains the data you are searching for (the value).

grantjenkins_1-1672845958477.png

 

Data is a Compose that contains your actual JSON data.

grantjenkins_2-1672846053410.png

 

XML is a Compose that converts your JSON data to XML. Note that we also add a root element to ensure it's valid XML. The expression used is:

xml(json(concat('{"root": { value:', outputs('Data'), '}}')))

grantjenkins_3-1672846149674.png

 

Finally, Output is a Compose that uses XPath to extract out the relevant property based on the Criteria, then gets the name of the property. It also needs to replace _x002F_ with / as XML converts this automatically, so we need to convert it back. The expression used is below.

replace(xpath(outputs('XML'), concat('name(//root/value/*[text()="', outputs('Criteria'), '"])')), '_x002F_', '/')

grantjenkins_4-1672846309738.png

 

The output using the criteria for this example is below:

grantjenkins_6-1672846407576.png


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.

View solution in original post

4 REPLIES 4
grantjenkins
Super User
Super User

It's difficult to get the actual property name by searching on the value when using JSON. In this instance I would convert your JSON to XML then use XPath to get what we want.

 

See full flow below. I'll go into each of the actions.

grantjenkins_0-1672845898865.png

 

Criteria is a Compose that contains the data you are searching for (the value).

grantjenkins_1-1672845958477.png

 

Data is a Compose that contains your actual JSON data.

grantjenkins_2-1672846053410.png

 

XML is a Compose that converts your JSON data to XML. Note that we also add a root element to ensure it's valid XML. The expression used is:

xml(json(concat('{"root": { value:', outputs('Data'), '}}')))

grantjenkins_3-1672846149674.png

 

Finally, Output is a Compose that uses XPath to extract out the relevant property based on the Criteria, then gets the name of the property. It also needs to replace _x002F_ with / as XML converts this automatically, so we need to convert it back. The expression used is below.

replace(xpath(outputs('XML'), concat('name(//root/value/*[text()="', outputs('Criteria'), '"])')), '_x002F_', '/')

grantjenkins_4-1672846309738.png

 

The output using the criteria for this example is below:

grantjenkins_6-1672846407576.png


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.


----------------------------------------------------------------------
If I've answered your question, please mark the post as Solved.
If you like my response, please consider giving it a Thumbs Up.
Taylor_Becktold
Resolver IV
Resolver IV

@hongdet  -

 

This is a tough one due to the structure of your JSON. What you are essentially trying to do is return the key in a key-value pair. Here are some examples of that: Retrieving Key using Select or Extracting key-value pair . @grantjenkins  also provided an excellent xpath solution as well. 

 

However, if you could restructure your JSON to look like this: 

 

{
"Timezones": [ 
{
"Name": "Pacific/Midway",
"Zone":"(UTC-11:00) Midway Island, Samoa" 
},
{
"Name": "Pacific/Pago_Pago",
"Zone":  "(UTC-11:00) Pago Pago"
}
]
}

 

 

You could simply parse the JSON using the 'Parse JSON' action and then use the 'Filter Array' action to filter on the 'Timezones' array where 'Zone' is equal to your user input. 

 

Outputs here is simply the JSON body I provided in the code snippetOutputs here is simply the JSON body I provided in the code snippet

 

Then, you can set a variable with 'Name' value returned from the 'filter array': 

Taylor_Becktold_3-1672846902894.png

Results from the 'filter array' action:

Taylor_Becktold_4-1672846973619.png

 

Results from setting the variable: 

Taylor_Becktold_5-1672846987043.png

 

Did my reply help? Please give it a thumbs up.
Did my reply answer your question? Please mark it as a solution!
If you liked my response, please consider giving it a thumbs up.

Check out my blog for more tips & tricks: https://azwhizkid.com/

 

Thank you @grantjenkins for the help! It's working now!! 🙂

Thank you @Taylor_Becktold for the help too!

Helpful resources

Announcements

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (5,189)