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 / Return number of keys ...
Power Automate
Answered

Return number of keys in a custom object

(0) ShareShare
ReportReport
Posted on by 169

I've converted JSON to a custom object.

 

The JSON:

{
"customerId":"cust3456",
"orderId":"or_4567",
"numItems":8
}

 

I convert it to a custom object named: varsObject

 

I can reference any of the keys and return the value but I'm looking to count the number of keys.

%Count(['varsObject'])%

- returns 1 - one object.

 

When I view the custom object, I see:

mmonline_0-1685727469380.png

 

How can I return the number of keys (fields) in the custom object.

 

Thanks.

  • Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @mmonline 

     

    I think custom object does not support count functions, That's really needed thing actually. I hope power automate will provide an update on this in future. 

     

    So until that , give a try this way

     

    1. In json string, check how many time colon (:) appears, because of no of colons represent the number of items in custom object.

     

    Hope that helps !

     

     

  • mmonline Profile Picture
    169 on at

    Thanks. I'll give that a try.

     

    However, I'm thinking I may also try to run javascript and parse the JSON. I know, with Javascript, I can definitely get the data I need. Then, output data about the JSON while using the object for parsing the data.

     

    To date, most of my work is with Google Apps Script and BigQuery for reporting. But a long-time client needs to integrate an internal SQL based accounting package with an eCommerce platform's API. I've prototyped some things with PowerShell as a solution.

     

    While on contract with Meta I built a PowerApps/Power Automate solution and want to see if this will work for my client. I am certain I can make it work and find some of the pre-built actions of Power Automate interesting. But I also find it far less dynamic and flexible than simply coding a solution. 

     

    Anyway.. thanks for replying. I'll try to remember to update this question when I create a solution.

  • Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hope u can resolve the same issue by coding / developing custom actions in power automate desktop which would be new feature going to be added

     

     

  • mmonline Profile Picture
    169 on at

    This is interesting. And by interesting, I mean, frustrating. 

     

    In my Run Javascript, I can pass JSON. I created a variable (Set Variable) with JSON. I named it orderJSON

    Then I add the Run Javascript - the return variable is: testObject

     

    var myJS =%orderJSON.length%
    WScript.Echo(myJS)

     The variable testObject is equal to the number of characters in the JSON.

     

    However, the following:

    var myJS = %orderJSON%
    var jsLen = myJS.length 
    WScript.Echo(jsLen)

    returns an error indicating the length property does not exist.

     

    If I simply echo the %orderJSON% as the javascript output, testObject is the same text as orderJSON.

    If I echo myJS (second example), testObject is an [Object].

     

    Finally, if I attempt to use something like:

    var newJS = Object.keys(%orderJSON%).length
    WScript.Echo(newJS)

     

    I receive the following error.

    C:\Users\MattMoran\AppData\Local\Temp\Robin\0sptrkpjjft.tmp(2, 1) Microsoft JScript runtime error: Object doesn't support this property or method

     

    I've also attempted to use JSON.parse() but it indicates that JSON is undefined.

     

    My understanding of the capabilities and available functions and methods of JScript is an issue, I suppose. 

     

    As it turns out, for what I need to accomplish, I won't need this... but it is something I believe would be helpful. Any thoughts on what I've posted?

  • Verified answer
    mwd86 Profile Picture
    100 on at

    hello you can count the keys with a python script. since your JSON has the same form as a dictionary.

     

    jsoncount.jpg

  • Verified answer
    DarijaSok Profile Picture
    7 on at

    1. Convert to Json using the Action

    2. Run powershell to retrieve Properties count

     

    Variables.ConvertCustomObjectToJson CustomObject: JsonAsCustomObject Json=> CustomObjectAsJson
    Scripting.RunPowershellScript.RunPowershellScript Script: $'''$jsonObject = ConvertFrom-Json \'%CustomObjectAsJson%\'
    $jsonObjectSize = $jsonObject | Get-Member -MemberType Properties | Measure-Object | Select-Object -ExpandProperty Count
    Write-Output $jsonObjectSize''' ScriptOutput=> size ScriptError=> ScriptError

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 227 Super User 2026 Season 2

#2
11manish Profile Picture

11manish 221 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 132

Last 30 days Overall leaderboard