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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How filter line start ...
Power Automate
Answered

How filter line start with in Json array

(0) ShareShare
ReportReport
Posted on by 11

Hi,
I need to capture the hostName information, but in the request for this json the hostName value is not always on the same line,

 

The only way I've found is to search for the hostName line by informing the desired line, in this case line 3

 

triggerBody()?['alert2']?['entities']?['entities'][3]

 

so creating rules to check if it has hostName:, if not, I set the variable to the next line and test the verification again, and so on until it finds hostName: in the variable

 

Json exemplo:

 

{
 "entities": [
 "fileName:c:\\windows\\regedit.exe",
 "hostId:8868979671",
 "hostName:REGLOST\\NT0547",
 "hostNameAndHostId:REGLOST\\NT0547:887571",
 "processImagePath:c:\\windows\\regedit.exe",
 "processUsername:AUTORIDADE NT\\SISTEMA",
 "programSha256:92f9f987a654x1658a7c4a0988ac918170",
 "sensorHostId:889754571",
 "sensorId:89873571",
 "userName:AUTORIDADE NT\\SISTEMA"
 ],
 "relationships": [
 {
 "from_entity": "hostName:REGLOST\\\\NT0547",
 "relationship": "is",
 "to_entity": "sensorHostId:88975471571"
 }
 ]
}

 

 

Another test I performed was the Filter array

 

@contains(triggerBody()?['alert2']?['entities'], 'hostName')

 

However, I noticed that my Json result does not seem to be formatted correctly so that my filter contains

BrunoGomes_0-1673534150036.png

my filter 'hostName' contains doesn't work for my inputs

 

I would like to understand if with the Json input that I have, it is possible for me to filter a line with some porator saying that it may contain more letters as in PowerShell as -like "hostName*"  using * as operator.

Would there be something in PowerAutomate that would do something like this? Or is there any other way that I don't need to get line by line if I have the desired information in my case?

 

Thanks.

Categories:
I have the same question (0)
  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @BrunoGomes 

     

    This is one way to do it if the hostname is always in the array, otherwise you will get an error on the split.

     

    Filter for the string hostName: where item() starts with:

    DamoBird365_1-1673542079370.png

    Then split the first() result in the filter on : and select the 2nd object [1].

     

    split(first(body('Filter_array')),':')?[1]


    Cheers
    Damien

    Please take a look and subscribe to my YouTube Channel for more Power Platform ideas and concepts. Thanks

  • BrunoGomes Profile Picture
    11 on at

    Thanks @DamoBird365

    I tested this way but went straight through the command

    @contains(triggerBody()?['alert2']?['entities'], 'hostName')

     

    what happens

    BrunoGomes_0-1673547243290.png

     

    BrunoGomes_2-1673547532693.png

     

    I get this array and error occurs

    [
     "fileName:c:\\windows\\regedit.exe",
     "hostId:8868979671",
     "hostName:REGLOST\\NT0547",
     "hostNameAndHostId:REGLOST\\NT0547:887571",
     "processImagePath:c:\\windows\\regedit.exe",
     "processUsername:AUTORIDADE NT\\SISTEMA",
     "programSha256:92f9f987a654x1658a7c4a0988ac918170",
     "sensorHostId:889754571",
     "sensorId:89873571",
     "userName:AUTORIDADE NT\\SISTEMA"
    ]

     InvalidTemplate. The execution of template action 'FilterArray-Entities-hostName:' failed: The evaluation of 'query' action 'where' expression '@startsWith(outputs('Array-Entities'), 'hostName:')' failed: 'The template language function 'startsWith' expects its first parameter to be of type string. The provided value is of type 'Array'. Please see https://aka.ms/logicexpressions#startswith for usage details.'.

     

    Applying the filter contains 'hostName:' not error occurs, but it finds nothing

     

    BrunoGomes_3-1673547998840.png

    BrunoGomes_4-1673548009137.png

    I have the array in INPUTS but in OUTPUTS the body is empty.

     

    Can you tell me what is going on that the Filter Array is not working? is it because of the format of my array?

     

    Thanks for the help!

     

     

     

  • DamoBird365 Profile Picture
    8,942 Microsoft Employee on at

    Hi @BrunoGomes 

     

    Your condition should be based on item() startswith and not the expression for the array. Your from in the filter is perfect.

     

    Damien

  • Verified answer
    Kaif_Siddique Profile Picture
    2,108 Super User 2024 Season 1 on at

    Hi @BrunoGomes ,

     

    Here is another solution. Customize the flow as per requirement:

    Kaif_Siddique_0-1673555613935.png

     

    Kaif_Siddique_1-1673555627985.png

     

    Hope this will help you

     

    Regards

    Kaif

     

  • BrunoGomes Profile Picture
    11 on at

    Hi, @Kaif_Siddique 

    Thats works!

    what I understand is that I need to use Parse JSON so that I have the data interpreted and I can model what I want.

     

    Thanks a lot!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 283

#2
David_MA Profile Picture

David_MA 256 Super User 2026 Season 1

#3
Expiscornovus Profile Picture

Expiscornovus 225 Most Valuable Professional

Last 30 days Overall leaderboard