cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
IFEJohn
Helper II
Helper II

Dynamic Values in Filter Array Source From

I am working with a JSON response that I need to query but the objects change (data types do not). In the example below, "2022-11-21:2" and "330.0" change all the time.

 

{
   "2022-11-21:2": {  
          "330.0": [{
                  "Field1": "TEST",
                   "Field2": "TEST"
           }],
            "333.0": [{
                   "Field1": "TEST",
                    "Field2": "TEST"
           }]
     }
}

 

So, I need to build an expression along the lines of:  body('Test')?['2022-11-21:2']?['330.0']

 

My question is...how do I include dynamic values in the expression? Or, is this not the best approach to parsing/querying the JSON?

19 REPLIES 19
grantjenkins
Super User
Super User

That's some very strange JSON output you're getting there 😕

 

What are you trying to get as final output? Will you be outputting just the values of the Field elements, or will you still be wanting to output "2022-11-21:2" and "330.0" as well?

 

If you can give us an example of what you'd like to see at the end, then we can work backwards to get what you're after.


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

Thank you for your response. Ha, I know it's strange...but the response of an API I don't have control over. My final output will be values of field elements. But I cannot simply reference array number...need to reference the specific "330" or "333"...which could be any number.

Is this the sort of output you were expecting? Or something else?

 

[
  {
    "Field 1": "One",
    "Field 2": "Two"
  },
  {
    "Field 1": "Three",
    "Field 2": "Four"
  }
]

 

The last thing I'm having trouble with is the single colon : within 2022-11-21:2.


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

Thank you @grantjenkins. I actually just need...

 

 

{
    "Field 1": "One",
    "Field 2": "Two"
}

 

 

 Yeah, that colon is a tricky part. It seems to be an array sequence number of some sort...strange usage.

grantjenkins
Super User
Super User

Just confirming - I'm assuming even the 2 after the colon could change to something else:

"2022-11-21:2


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

Yes, that value can change too, unfortunately. It is some kind of sequence number.

Ajinder31
Continued Contributor
Continued Contributor

@IFEJohn May we know if this response is from a Custom connector or existing published connectors? If it's from custom connector then do you have edit access to the connector.

The reason I am asking because I worked with similar scenario while working on a custom connector and Policy Object to Array helped me in my case. 

IFEJohn
Helper II
Helper II

It’s the response from an API call using the HTTP connector. 

Ajinder31
Continued Contributor
Continued Contributor

Hi @IFEJohn , I think we can go Custom connector route in this case as Http also requires a premium license (as per my knowledge). Custom connector also gives us the flexibility to transform response as required using custom code as well. 

At the same time, there might be better solution available which I am not aware of. 

I think I've got that rouge colon sorted. Just wanted to confirm a couple more things.

 

What will the field names be? At the moment you have Field1 and Field2, but what are some of the actual field names (or are those them)?

 

And will the field names always be the same?


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

@Ajinder31 Thanks for your suggestion, but I think building a custom connector for this is not a good approach for my use case.

 

@grantjenkins Wow, thank you! I really appreciate it. There are a lot of fields, but a couple would be "High Price" and "Low Price". Yes, the field names will always be the same.

grantjenkins
Super User
Super User

Ok, so a bit messy with quite a few replace expressions to clean up the raw input but should get what you're after.

 

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

grantjenkins_0-1669097053582.png

 

Data is a Compose action that contains the raw JSON input.

grantjenkins_1-1669097394406.png

{
    "2022-11-2122:2": {
        "330.0": [
            {
                "Field1": "One",
                "Field2": "Two"
            }
        ],
        "333.0": [
            {
                "Field1": "Three",
                "Field2": "Four"
            }
        ]
    }
}

 

Compose uses a few replace expressions to remove the colon between (in this example) 2122 and 2. It should work regardless of where it is. It actually replaces the valid colons temporarily, then replaces (removes) the non-valid one(s), and finally replaces the valid ones back to their original state. The expression used here is:

replace(replace(replace(string(outputs('Data')), '":', '"+'), ':', ''), '"+', '":')

grantjenkins_2-1669097544111.png

 

XML is another Compose that replaces (removes) any periods and new lines, then converts the JSON to XML so we can use XPath. The expression used here is:

xml(json(replace(replace(concat('{"root": ', outputs('Compose'), '}'), '.', ''), decodeUriComponent('%0A'), '')))

grantjenkins_3-1669097677984.png

 

The actual XML output we get here is:

<root>
  <_x0032_022-11-21222>
    <_x0033_300>
      <Field1>One</Field1>
      <Field2>Two</Field2>
    </_x0033_300>
    <_x0033_330>
      <Field1>Three</Field1>
      <Field2>Four</Field2>
    </_x0033_330>
  </_x0032_022-11-21222>
</root>

 

Finally, we have a Select to get our JSON output using XPath.

grantjenkins_4-1669097873873.png

 

The input uses the following expression so that we can iterate over each of the fields.

xpath(outputs('XML'), '//root/*/*')

 

The expressions to get the field values (for this example) are below. Note that you would just need to change the field names to match what you have in your JSON.

xpath(item(), 'string(//Field1/text())')
xpath(item(), 'string(//Field2/text())')

 

This would give us the output below.

[
  {
    "Field 1": "One",
    "Field 2": "Two"
  },
  {
    "Field 1": "Three",
    "Field 2": "Four"
  }
]

 

You should then be able to use standard JSON to get what you're after.


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

@grantjenkins Thank you SO much for taking the time to work on this. I really appreciate it. As much as I would love to say this is what I am looking for, it is a bit off. To add more context to my first post, I am looking to query the JSON payload with something like body('Test')?['2022-11-21:2']?['330.0']...but be able to pass in the date and "330.0" values as they will change. Am I missing something or does your approach allow me to do that? 

If you wanted to get the second object you could do the following:

body('Select')[1]

grantjenkins_1-1669175574089.png

 

If you wanted to get the value of Field 2 from the first object you could do the following:

body('Select')[0]?['Field 2']

grantjenkins_0-1669175536926.png

 

Is that what you were after?


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

@grantjenkins Thank you. Yes, I understand that, but I need to pass the dynamic date and decimal values into the select query. I wont know which object number a given record will be in the array. Make sense? 

grantjenkins
Super User
Super User

@IFEJohn Sorry, I'm not actually sure what you after in that sense. How will you know what to query if you don't know what it will be?


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

@grantjenkins The values that are used to query are dynamic based on other actions in the flow...which is why I need the query string.

I think I may have completely misunderstood (and over complicated) what you were after initially 🙂

 

Is this what you are after? Note the expression used for Compose Output is:

outputs('Compose')?[variables('date')]?[variables('time')]

 

grantjenkins_0-1669511270257.png

 

This would result in:

grantjenkins_1-1669511369562.png

 

Then if you just wanted to get the object from the array you could append [0] to the expression or wrap the entire expression with first.

 

first(outputs('Compose')?[variables('date')]?[variables('time')])

 


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

@grantjenkins Thank you! Yes, this is what I was looking for. Seems so simple now that I see it. Ha. I think I was simply not using the correct syntax. I appreciate your help.

Helpful resources

Announcements

April 2024 Community Newsletter

We're pleased to share the April Community Newsletter, where we highlight the latest news, product releases, upcoming events, and the amazing work of our outstanding Community members.   If you're new to the Community, please make sure to follow the latest News & Announcements and check out the Community on LinkedIn as well! It's the best way to stay up-to-date with all the news from across Microsoft Power Platform and beyond.    COMMUNITY HIGHLIGHTS   Check out the most active community members of the last month! These hardworking members are posting regularly, answering questions, kudos, and providing top solutions in their communities. We are so thankful for each of you--keep up the great work! If you hope to see your name here next month, follow these awesome community members to see what they do!   Power AppsPower AutomateCopilot StudioPower PagesWarrenBelzDeenujialexander2523ragavanrajanLaurensMManishSolankiMattJimisonLucas001AmikcapuanodanilostephenrobertOliverRodriguestimlAndrewJManikandanSFubarmmbr1606VishnuReddy1997theMacResolutionsVishalJhaveriVictorIvanidzejsrandhawahagrua33ikExpiscornovusFGuerrero1PowerAddictgulshankhuranaANBExpiscornovusprathyooSpongYeNived_Nambiardeeksha15795apangelesGochixgrantjenkinsvasu24Mfon   LATEST NEWS   Business Applications Launch Event - On Demand In case you missed the Business Applications Launch Event, you can now catch up on all the announcements and watch the entire event on-demand inside Charles Lamanna's latest cloud blog.   This is your one stop shop for all the latest Copilot features across Power Platform and #Dynamics365, including first-hand looks at how companies such as Lenovo, Sonepar, Ford Motor Company, Omnicom and more are using these new capabilities in transformative ways. Click the image below to watch today!   Power Platform Community Conference 2024 is here! It's time to look forward to the next installment of the Power Platform Community Conference, which takes place this year on 18-20th September 2024 at the MGM Grand in Las Vegas!   Come and be inspired by Microsoft senior thought leaders and the engineers behind the #PowerPlatform, with Charles Lamanna, Sangya Singh, Ryan Cunningham, Kim Manis, Nirav Shah, Omar Aftab and Leon Welicki already confirmed to speak. You'll also be able to learn from industry experts and Microsoft MVPs who are dedicated to bridging the gap between humanity and technology. These include the likes of Lisa Crosbie, Victor Dantas, Kristine Kolodziejski, David Yack, Daniel Christian, Miguel Félix, and Mats Necker, with many more to be announced over the coming weeks.   Click here to watch our brand-new sizzle reel for #PPCC24 or click the image below to find out more about registration. See you in Vegas!       Power Up Program Announces New Video-Based Learning Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram. These include 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 image below to find out more!   UPCOMING EVENTS Microsoft Build - Seattle and Online - 21-23rd May 2024 Taking place on 21-23rd May 2024 both online and in Seattle, this is the perfect event to learn more about low code development, creating copilots, cloud platforms, and so much more to help you unleash the power of AI.   There's a serious wealth of talent speaking across the three days, including the likes of Satya Nadella, Amanda K. Silver, Scott Guthrie, Sarah Bird, Charles Lamanna, Miti J., Kevin Scott, Asha Sharma, Rajesh Jha, Arun Ulag, Clay Wesener, and many more.   And don't worry if you can't make it to Seattle, the event will be online and totally free to join. Click the image below to register for #MSBuild today!   European Collab Summit - Germany - 14-16th May 2024 The clock is counting down to the amazing European Collaboration Summit, which takes place in Germany May 14-16, 2024. #CollabSummit2024 is designed to provide cutting-edge insights and best practices into Power Platform, Microsoft 365, Teams, Viva, and so much more. There's a whole host of experts speakers across the three-day event, including the likes of Vesa Juvonen, Laurie Pottmeyer, Dan Holme, Mark Kashman, Dona Sarkar, Gavin Barron, Emily Mancini, Martina Grom, Ahmad Najjar, Liz Sundet, Nikki Chapple, Sara Fennah, Seb Matthews, Tobias Martin, Zoe Wilson, Fabian Williams, and many more.   Click the image below to find out more about #ECS2024 and register today!     Microsoft 365 & Power Platform Conference - Seattle - 3-7th June If you're looking to turbo boost your Power Platform skills this year, why not take a look at everything TechCon365 has to offer at the Seattle Convention Center on June 3-7, 2024.   This amazing 3-day conference (with 2 optional days of workshops) offers over 130 sessions across multiple tracks, alongside 25 workshops presented by Power Platform, Microsoft 365, Microsoft Teams, Viva, Azure, Copilot and AI experts. There's a great array of speakers, including the likes of Nirav Shah, Naomi Moneypenny, Jason Himmelstein, Heather Cook, Karuana Gatimu, Mark Kashman, Michelle Gilbert, Taiki Y., Kristi K., Nate Chamberlain, Julie Koesmarno, Daniel Glenn, Sarah Haase, Marc Windle, Amit Vasu, Joanne C Klein, Agnes Molnar, and many more.   Click the image below for more #Techcon365 intel and register today!     For more events, click the image below to visit the Microsoft Community Days website.      

Tuesday Tip | Update Your Community Profile Today!

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.   We're excited to announce that updating your community profile has never been easier! Keeping your profile up to date is essential for staying connected and engaged with the community.   Check out the following Support Articles with these topics: Accessing Your Community ProfileRetrieving Your Profile URLUpdating Your Community Profile Time ZoneChanging Your Community Profile Picture (Avatar)Setting Your Date Display Preferences Click on your community link for more information: Power Apps, Power Automate, Power Pages, Copilot Studio   Thank you for being an active part of our community. Your contributions make a difference! Best Regards, The Community Management 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  

Super User of the Month | Ahmed Salih

We're thrilled to announce that Ahmed Salih is our Super User of the Month for April 2024. Ahmed has been one of our most active Super Users this year--in fact, he kicked off the year in our Community with this great video reminder of why being a Super User has been so important to him!   Ahmed is the Senior Power Platform Architect at Saint Jude's Children's Research Hospital in Memphis. He's been a Super User for two seasons and is also a Microsoft MVP! He's celebrating his 3rd year being active in the Community--and he's received more than 500 kudos while authoring nearly 300 solutions. Ahmed's contributions to the Super User in Training program has been invaluable, with his most recent session with SUIT highlighting an incredible amount of best practices and tips that have helped him achieve his success.   Ahmed's infectious enthusiasm and boundless energy are a key reason why so many Community members appreciate how he brings his personality--and expertise--to every interaction. With all the solutions he provides, his willingness to help the Community learn more about Power Platform, and his sheer joy in life, we are pleased to celebrate Ahmed and all his contributions! You can find him in the Community and on LinkedIn. Congratulations, Ahmed--thank you for being a SUPER user!

Tuesday Tip: Getting Started with Private Messages & Macros

Welcome to 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!   This Week's Tip: Private Messaging & Macros in Power Apps Community   Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member!   Our Knowledge Base article about private messaging and macros is the best place to find out more. Check it out today and discover some key tips and tricks when it comes to messages and macros:   Private Messaging: Learn how to enable private messages in your community profile and ensure you’re connected with other community membersMacros Explained: Discover the convenience of macros—prewritten text snippets that save time when posting in forums or sending private messagesCreating Macros: Follow simple steps to create your own macros for efficient communication within the Power Apps CommunityUsage Guide: Understand how to apply macros in posts and private messages, enhancing your interaction with the Community For detailed instructions and more information, visit the full page in your community today:Power Apps: Enabling Private Messaging & How to Use Macros (Power Apps)Power Automate: Enabling Private Messaging & How to Use Macros (Power Automate)  Copilot Studio: Enabling Private Messaging &How to Use Macros (Copilot Studio) Power Pages: Enabling Private Messaging & How to Use Macros (Power Pages)

Tuesday Tip: Subscriptions & Notifications

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!   This Week: All About Subscriptions & Notifications We don't want you to a miss a thing in the Community! The best way to make sure you know what's going on in the News & Announcements, to blogs you follow, or forums and galleries you're interested in is to subscribe! These subscriptions ensure you receive automated messages about the most recent posts and replies. Even better, there are multiple ways you can subscribe to content and boards in the community! (Please note: if you have created an AAD (Azure Active Directory) account you won't be able to receive e-mail notifications.)   Subscribing to a Category  When you're looking at the entire category, select from the Options drop down and choose Subscribe.     You can then choose to Subscribe to all of the boards or select only the boards you want to receive notifications. When you're satisfied with your choices, click Save.     Subscribing to a Topic You can also subscribe to a single topic by clicking Subscribe from the Options drop down menu, while you are viewing the topic or in the General board overview, respectively.     Subscribing to a Label Find the labels at the bottom left of a post.From a particular post with a label, click on the label to filter by that label. This opens a window containing a list of posts with the label you have selected. Click Subscribe.     Note: You can only subscribe to a label at the board level. If you subscribe to a label named 'Copilot' at board #1, it will not automatically subscribe you to an identically named label at board #2. You will have to subscribe twice, once at each board.   Bookmarks Just like you can subscribe to topics and categories, you can also bookmark topics and boards from the same menus! Simply go to the Topic Options drop down menu to bookmark a topic or the Options drop down to bookmark a board. The difference between subscribing and bookmarking is that subscriptions provide you with notifications, whereas bookmarks provide you a static way of easily accessing your favorite boards from the My subscriptions area.   Managing & Viewing Your Subscriptions & Bookmarks To manage your subscriptions, click on your avatar and select My subscriptions from the drop-down menu.     From the Subscriptions & Notifications tab, you can manage your subscriptions, including your e-mail subscription options, your bookmarks, your notification settings, and your email notification format.     You can see a list of all your subscriptions and bookmarks and choose which ones to delete, either individually or in bulk, by checking multiple boxes.     A Note on Following Friends on Mobile Adding someone as a friend or selecting Follow in the mobile view does not allow you to subscribe to their activity feed. You will merely be able to see your friends’ biography, other personal information, or online status, and send messages more quickly by choosing who to send the message to from a list, as opposed to having to search by username.

Users online (4,164)