How to filter a JSON object with dynamic keys with Power Automate

Поділитися
Вставка
  • Опубліковано 5 вер 2024
  • This video explains how to filter a JSON object in #powerautomate which has dynamic key value pairs. Because the filter array action expects you to know the key name before you can filter on it, this can be difficult to achieve.
    This technique is one that I haven't used before so I thought it was interesting to share. The original forum post is here:
    powerusers.mic...

КОМЕНТАРІ • 32

  • @tuhan4780
    @tuhan4780 9 місяців тому +1

    Hey, thank you for sharing this solution, was really struggling with same problem!(Property names for me were dynamic dataverse IDs which I needed to updated, and keys were True\false values defining if this ID needs an update)
    For anyone who would come across this solution I`ll post all formulas down here:
    createArray(body('Post_Card')['data'])
    split(trim(body('Create_CSV_table')),decodeUriComponent('%0D%0A'))
    range(0,length(split(outputs('Split_CSV')[0],',')))
    split(outputs('Split_CSV')[0],',')[item()]
    split(outputs('Split_CSV')[1],',')[item()]

  • @nguyenmanhtuan1772
    @nguyenmanhtuan1772 4 місяці тому

    Thank you very much Sir.
    You have always been one of the most of my favorite channels when I seek solutions for my concerns. I am lucky to know your channel.

    • @PaulieM
      @PaulieM  4 місяці тому +1

      That’s very kind of you, thank you! 🙏

  • @jasonbuchek
    @jasonbuchek 2 місяці тому

    100% like everyone else has said, you are the man sir!
    Subbing now

  • @joel.engelhardt
    @joel.engelhardt Рік тому

    Hey, thank you for sharing this! I was scratching my head for a while trying to figure this out, and this is the EXACT solution I needed. I'm needed this exact solution to process the key-value pairs from the "Get changes for an item or a file" action. Thank you! You're very generous.

    • @PaulieM
      @PaulieM  Рік тому

      You're very welcome!

  • @EnlightenedOne90
    @EnlightenedOne90 Рік тому +1

    Another great vid Paulie, thank you! Will be adding this solution to my toolbox for future use.

    • @PaulieM
      @PaulieM  Рік тому

      Thank you Jeremy! This was a tricky one!

  • @codelessstudio1269
    @codelessstudio1269 6 місяців тому

    Exactly what i'm looking for, thanks for sharing Paul :)

    • @PaulieM
      @PaulieM  6 місяців тому

      Great to hear!

  • @joti8818
    @joti8818 Рік тому

    Brilliant solution! Thank you very much for sharing!

  • @motisko
    @motisko 11 днів тому

    Very slick way of interfacing with this. I hit a snag implementing it since I wanted to expand this to all general JSON objects to key pairs. If any of the values have a comma in then, as you can imagine this craps the bed. Challenge you to find how to escape those inline text commas?

    • @PaulieM
      @PaulieM  10 днів тому

      I will take that challenge 😂 send me a text file containing your example JSON please?

    • @motisko
      @motisko 10 днів тому

      @@PaulieM Thanks for entertaining this. I've scrubbed some of the data here but just add some commas into the value pairs or even quotes. Looking for a robust solution that can handle the dynamic nature of the key values in addition to handling escape characters, additional commas, or inline quotes or even when the object comes back with number values not in quotes within the object for the value. This is a sample JSON object I get back from an SQL that I loop through and parse this one item out.
      It starts going off the rails when trying to split on the comma as inline commas in the value can't tell the differences from the ones at the end and that starts to cascade into other issues with quotes in the values later as well.
      [
      {
      "@odata.etag": "",
      "ItemInternalId": "c073da9d-c751-4342-ae25-c9b4c4854b07",
      "Id": 1179773000021739000,
      "Opportunity Name": "XYZ",
      "Procurement Status": "ABC",
      "Opportunity Summary": "This requirement shall include all technical, management, and quality control processes required to enable the Agency to plan, design, configure, implement, deliver, operate, and enhance More XYZ. he scope of the requirement encompasses the major objective areas listed below. For related background, see the Attachments to the SOO.",
      "Contract Vehicle": "[\"UNDETERMINED\"]",
      "Capability Alignment": "[\"Design\",\"Development\",\"Testing\",\"Engineering\",\"Integration\"]",
      "Solicitation Number": 123,
      "No. of Expected Awards": "Multiple - Number Unknown",
      "Value (TCV $)": 1,
      "Duration": 60,
      "Value (OCV$)": 1,
      "Competition Type _x002d_ Socio_x002d_Economic _x0026_ Size": "[\"Undetermined\"]",
      "pWin": 10,
      "Opportunity Type": "New Contract - New Customer",
      "Time Phase Factored Revenue": "0",
      "Factored OCV": "0.1",
      "Last Activity Time": "2024-08-23T14:27:38",
      "Unique Identifier": "998",
      "Opportunity Description": "This Statement of Objectives (SOO) for a multiple award Blanket Purchase Agreement (BPA) outlines the broad objectives of the AGENCY to improve business workflows through utilizing “Low-Code/No-Code” Platforms to enhance the delivery of modernized applications. As it relates to this requirement, Low-Code/No-Code Platforms are a software development environment that allows users to create applications without having to write code. This can be done by using a graphical user interface (GUI) to drag and drop components, or by using a visual programming language. This definition is Platform agnostic. By leveraging the integrated platforms’ capabilities, AGENCY can achieve greater efficiency, agility, and innovation."
      }
      ]

  • @RealIndianEmotion
    @RealIndianEmotion Рік тому +1

    Saved the day, Many thanks!

  • @bluric0
    @bluric0 Місяць тому

    Didn't work for me unfortunately. It looks like my outputs contain nested arrays that are also split with comma so not sure how to get around that!

  • @lubeshbehera1993
    @lubeshbehera1993 Рік тому

    woah impressive !!!

  • @mr_grucha
    @mr_grucha Рік тому

    Best hack I have ever seen

  • @davidezequielmonti663
    @davidezequielmonti663 8 місяців тому

    Hey, nice video! How could you do to go backwards? I mean, going from that Array to a dynamic key value pairs object? Thanks a lot!

    • @PaulieM
      @PaulieM  8 місяців тому

      Do you have an example input and desired output you can provide?

  • @kylecarnaroli5062
    @kylecarnaroli5062 Рік тому

    Great Tutorial, wish it helped with my situation, but unfortunately there are commas inside of the dynamic keys and this throws the split off.

    • @PaulieM
      @PaulieM  Рік тому

      Would be interested in having a look at your sample.

  • @neeltiwari6147
    @neeltiwari6147 3 місяці тому

    If i have output of parse jason like this {
    data:
    {
    “data1”:”one”,
    “data2”:””,
    “data3”:”data3”
    }
    }
    now you can see data two value is just empty “”
    so i want to remove data two and want output like this
    {
    data:
    {
    “data1”:”one”,
    “data3”:”data3”
    }
    }
    how to achieve this for you have any idea?

    • @samaccsamacc7963
      @samaccsamacc7963 20 днів тому

      in filter array use string('') remaining all same

  • @bluric0
    @bluric0 Місяць тому

    Will this work with complex JSON that includes Objects and Arrays with objects? I am going to give it a go, but essentially depending on the config of said item, the output of JSON Objects and arrays change continuously. I am trying to work out a method to dynamically update the outputs for all values that do not contain null into a word document. Essentially the end goal is creating documentation for the config itself. If your interested to give it a go, let me know and I can send you a sample of some data I have, but essentially the output will come directly out of a HTTP REST API.

    • @PaulieM
      @PaulieM  25 днів тому

      Use the get in touch form on my blog and I will take a look

  • @matiaskezman1
    @matiaskezman1 Рік тому

    Hello, thank you for sharing. Do you have any suggestions on the following scenario: my json has comments data which mesns that I could have a comma in the text. The comma split doesn't work in this scenario.

    • @PaulieM
      @PaulieM  Рік тому +1

      It’s always tricky in this case. I’d be interested to take a look at it with you.

    • @matiaskezman1
      @matiaskezman1 Рік тому +1

      @@PaulieM Thank you for responding. How would you like to connect ? I'm currently working on a way to do this using xpath, but having a hard time with getting the values (I've got the keys correctly). Your suggestions are much appreciated!

    • @PaulieM
      @PaulieM  Рік тому +1

      @@matiaskezman1 please fill in the contact form on my blog.

  • @navarrocloud
    @navarrocloud Рік тому

    Very nice hack.