How to perform a string function on a parsed JSON array value in a for each loop

David Beaven 141 Reputation points
2022-12-12T14:18:23.25+00:00

I want to use the slice function to return a substring but it won't cast from array to string:

"value": "@{slice(items('For_each')?['hostname'],2)}"

InvalidTemplate. Unable to process template language expressions in action 'Insert_row_(V2)' inputs at line '0' and column '0': 'The template language function 'slice' expects its first parameter to be of type string. The provided value is of type 'Array'. Please see https://aka.ms/logicexpressions#slice for usage details.'.

Thanks

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,542 questions
0 comments No comments
{count} votes

Accepted answer
  1. Taylor Becktold 226 Reputation points
    2022-12-12T17:28:45.477+00:00

    Hey David -

    I hope I can help. I was able to test this and got it working in my environment. Would you be able to provide the following so I can assist?

    1. Screenshot of the for-each loop that contains the action where this is failing
    2. The raw output/JSON of the action that is driving the for each loop.

    You can redact the raw output/JSON as much as you want, I just want to see the attribute ['hostname'] and ensure it is indeed a string and not an array nested into the JSON.

    Thanks!

    Did my reply help? Please give it a thumbs up.
    Did my reply answer your question? Please mark it as a solution!
    If you liked my response, please consider giving it a thumbs up.
    Check out my blog: https://azwhizkid.com/


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.