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 / Convert JSON object wi...
Power Automate
Unanswered

Convert JSON object with dynamic keys to array of keys

(0) ShareShare
ReportReport
Posted on by
Hi all, 
 
I'm stuck with this "little" problem for hours now - and I'm getting desperate...
 
I followed this suggested similar topic: https://community.powerplatform.com/forums/thread/details/?threadid=69bda654-a4b0-46e8-9f55-75d2d08fcab9 without a solution for me (although I have the exact same problem!).
 
For my `Compose` action (following a `Parse JSON` action) with
replace(string(outputs('JSON_analysieren')), 'body', 'root')
to wrap a `root` around the JSON (instead of `body`), I get this output:
{"root":{"Spalte1":"abc","Spalte2":"bcd","Spalte3":"cde"}}
which seems fine to me.
 
Next I try
xpath(xml(outputs('Verfassen_2')), '/root/*')
but already the `xml()` part throws the following error:
Unable to process template language expressions in action 'Verfassen_4' inputs at line '0' and column '0': 'The template language function 'xml' parameter is not valid. The provided value cannot be converted to XML: 'Data at the root level is invalid. Line 1, position 1.'. Please see https://aka.ms/logicexpressions#xml for usage details.'.
 
I just want an array with all the keys (Spalte1, Spalte2, Spalte3) without hard coding them.
 
 
Could someone please help me and tell me, what I'm doing wrong?
 
Thanks and best regards
Stefan
 
Categories:
I have the same question (0)
  • David_MA Profile Picture
    14,090 Super User 2026 Season 1 on at
    Could you explain what you need instead of referring to another post that doesn't seem related to the need? I don't really understand your end goal. Do you want to generate the following JSON array data:
     
    [
        {"key": "Spalte1"},
        {"key": "Spalte2"},
        {"key": "Spalte3"}
    ]
     
    If so, now I now know your objective. Now show how you are getting the data that you need to transform to the above. If this isn't your end objective, please clarify as to what it is. I don't see how using the xpath for XML data is related to getting something into a JSON array which may be why you are struggling.
     
  • SH-05111713-0 Profile Picture
    on at
    @David MA
     
    my goal is getting an array with the key / property names.
     
    Either
    [
        {"key": "Spalte1"},
        {"key": "Spalte2"},
        {"key": "Spalte3"}
    ]
    or
    [
        "Spalte1",
        "Spalte2",
        "Spalte3"
    ]
    to be able to iterate through an array of not hard coded column names.
     
     
     
    Now I'm using `Compose` with 
    first(outputs('In_Tabelle_vorhandene_Zeilen_auflisten')?['body/value'])
    and get the first row of a table from within Excel (from `List rows in a table`):
    {
        "@odata.etag": "",
        "ItemInternalId": "xxxxxxx",
        "Spalte1": "abc",
        "Spalte2": "bcd",
        "Spalte3": "cde"
    }
     
    By using 
    removeProperty(
      removeProperty(
        json(
          replace(
            string(outputs('Verfassen')),'@odata.','odata')),
        'odataetag'),
      'ItemInternalId')
     
     
    I remove the unrelevant properties and get
    {
        "Spalte1": "abc",
        "Spalte2": "bcd",
        "Spalte3": "cde",
    }
    Then I use `Parse JSON` with the schema
    {
        "type": "object",
        "properties": {
            "Spalte1": {
                "type": "string"
            },
            "Mitarbeiterkreis": {
                "type": "string"
            },
            "Spalte2": {
                "type": "string"
            },
            "Spalte3": {
                "type": "string"
            }
        }
    }
    to get
    {
        "body": {
            "Spalte1": "abc",
            "Spalte2": "bcd",
            "Spalte3": "cde"
        }
    }
    Afterwards I use 
    replace(string(outputs('JSON_analysieren')), 'body', 'root')
    and
    xpath(xml(outputs('Verfassen_2')), '/root/*')
    to end with the mentioned error.
     
     
  • Chriddle Profile Picture
    8,672 Super User 2026 Season 1 on at
    Your data and expressions work fine here:
     

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!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 592

#2
Valantis Profile Picture

Valantis 340

#3
11manish Profile Picture

11manish 284

Last 30 days Overall leaderboard