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

Notifications

Announcements

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
    12,982 Super User 2025 Season 2 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,443 Super User 2025 Season 2 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 519 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 296 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard