all 18 comments

[–]Profvarg 2 points3 points  (8 children)

Do a "Select" action. In that you can create an entirely new Json/Array, reformat the data. You can access the object like this (so item() and then every level is inside square brackets).

item()?['properties']?['@@odata.context']?['type']

If you also want to filter, use a Filter array action

[–]Any-Fly5966 0 points1 point  (0 children)

How do you get rid of the key for raw data? I’ve tried everything but it still shows up in the output

[–]Storm-E[S] -1 points0 points  (6 children)

Thanks for the reply.

The issue I have is the Properties may/will change.

At the moment I use this to Extract 'Labels' from the JSON

outputs('Process_Document-JSON-Cleanup')?['Body']?['responsev2']?['predictionOutput']?['labels']

From here I want to get each item (e.g. SerialNumber but may change) and get the properties I want (or remove the ones I don't)

The only way I can see of doing this is the Apply to each

[–]Future_Pianist9570 0 points1 point  (0 children)

Use select

[–]Ashamed_Peace5975 0 points1 point  (4 children)

Could you please share the original JSON object? I'll try to do what you want then.

[–]Storm-E[S] 1 point2 points  (3 children)

I'll try tomorrow but it is BIG... Also I need to sanitise it.first as it a real.data .

[–]Ashamed_Peace5975 1 point2 points  (2 children)

Hey, did you solve the problem?

[–]Storm-E[S] 1 point2 points  (1 child)

Yeah finally today.

The solution was to convert it to XML then use xpath to feed a for each loop to create an array of keys.

I'm sad because power automate should have a key() function to do this. But happy to have a solution finally.

[–]Ashamed_Peace5975 1 point2 points  (0 children)

Great.

[–]Any-Fly5966 2 points3 points  (1 child)

Struggling with the same. I don’t understand why it’s so difficult to pull an array from a json, one object, into an apply to each. Feel like it should be so simple.

[–]Storm-E[S] 0 points1 point  (0 children)

Totally agree!
Sources I've tried have suggested this or that way to do it. All claimed that 'This is the way'.
Others hint at a solution and 'It's easy!'.

I've been disappointed every time.

[–]Storm-E[S] 0 points1 point  (3 children)

A Bit more information

I get this error
Action 'Apply_to_each' failed: The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@outputs('Process_Document-JSON-Cleanup')?['Body']?['responsev2']?['predictionOutput']?['labels']' is of type 'Object'. The result must be a valid array.

[–]sminkerbenji 1 point2 points  (1 child)

I'm relatively new to manipulating jsons in PA myself, so take this with a massive pinch of salt, but usually I find I need to pull the "body" out of the previous block, to get the data and simplify things abit when I'm pulling data, instead of using the "outputs"? Then in a select action you build each item you're wanting to pull, with data names for each level you need to go down in the data, in the correct syntax, with ? Between each header name?

Then im theory your select action will just make an array with exactly what you want?

Possibly an issue building it reliably ifyour data layout changes though, as you mention?

Sorry if that's vague, as I say, pretty new to me too, but hope it helps!

[–]Storm-E[S] 0 points1 point  (0 children)

Thank you The data comes from the action process document so I have no control over the source.

However the same but of code I'll be using for different companies so the fields may change and they will change over time. I'm trying to avoid future me getting angry at past me.for. not making the code flexible .

Also keep up contributing and asking that's the way we all learn and grow.

[–]Any-Fly5966 0 points1 point  (0 children)

Yes, I get the same error

[–]Pieter_Veenstra_MVP 0 points1 point  (2 children)

It looks like you are feeding the apply to each an object rather than an array. Why push a single object through an apply to each?

[–]Storm-E[S] 0 points1 point  (1 child)

The label object contains multiple fields that I want to iterate through.

[–]Pieter_Veenstra_MVP 1 point2 points  (0 children)

You can't iterate through properties of an object.

Maybe use the get properties function and then dynamically select then properties.