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 Automate
Answered

Json to Array Issue

(0) ShareShare
ReportReport
Posted on by 32

Hi, really struggling with a flow processing engineer jobsheets.

 

It receives a HTTP request from their PDA's, processes the Json and adds it into two sharepoint list consisting of general information, and products used.

 

Everything in the general list gets added fine, but the products list is a little more troublesome.

 

  • If there are no products listed, then the flow works perfectly.
  • If there are two products, then the flow works perfectly.
  • If there is one product, then the flow fails, with the following error:

 

Unable to process template language expressions for action 'Condition_2' at line '1' and column '2352': 'The template language function 'length' expects its parameter to be an array or a string. The provided value is of type 'Object'. Please see https://aka.ms/logicexpressions#length for usage details.'.

 

 

If there is nothing in the array, then it will return Empty as 'true' in a condition, and exit the  flow. If there are two products listed, then it processes fine in the 'Apply to Each' part of the flow importing the products.

 

I believe the issue I'm having is in the way that the Json is submitted from the PDA manufacturer.

Example of Two products in the Raw Json submitted via the HTTP request.

 "Product1": [
 {
 "Qty": "3",
 "Barcode": null,
 "Item": "Eggs",
 "Price": "3.50"
 },
 {
 "Qty": "4",
 "Barcode": null,
 "Item": "Boxes",
 "Price": "66.00"
 }
 ],

however when there is just one product, the below is the raw json:

 "Product1": {
 "Qty": "4",
 "Barcode": null,
 "Item": "Boxes",
 "Price": "66.00"
 },

I believe my issues are relating to the fact that when there is one product, it's considered a string, rather than an array by the flow.

 

I'm at the end of my knowledge and would really appreciate some help processing the data what ever number of products are listed.

 

 

Categories:
  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @MrRK,

     

    Could you please show a bit more about the two SharePoint lists that you mentioned?

    Further, could you please share a screenshot of your flow's configuration?

     

    The error message told that the length() function expects its parameter to be an array or a string, but you provide an Object wihtin it. The length() function could not return the number of elements in an Object. More details about the length() function, please check the following article:

    https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-definition-language#functions

     

    I assume that you could get the corresponding content of the Product1 property within Ram json in your flow. If you want your flow to work well when there is one product, you should check if the Raw json is array or object firstly within your flow. If the Raw json is an object, you should convert the Object into an array at first.

     

    I have made a test on my side and please take a try with the following workaround:

    • Add a proper trigger, here I use Flow Button trigger.
    • Add a Compose action, Inputs set to Raw json dynamic content from the HTTP request your side. On my side, Inputs set to following Raw json for testing:
    {
     "Qty": "3",
     "Barcode": null,
     "Item": "Eggs",
     "Price": "3.50"
    }
    • Add a Variables-> "Initialize variable" action, Name set to FinalArray, Type set to Array and Value set to empty.
    • Add a Variables-> "Initialize variable 2" action, Name set to InitializeArray, Type set to Array and Value set to output of "Compose" action.
    • Add a Parallel branch action, within left branch, add a "Set variable 2" action, Name choose FinalArray, Value set to output of "Compose" action. Within right branch, add a Scope action, within Scope action, add a "Compose 2" action, Inputs set to following formula:
    array(outputs('Compose'))

    Add a "Set variable" action, Name choose FinalArray variable, Value set to output of "Compose 2" action. Then click "Menu" button of Scope action as below:14.JPG

    Then click "Configure run after", within "Scope should run after" panel, select has failed option and click "Done".

     

    • Under the "Parallel branch" action, add a "Compose 3" action, Inputs set to following formula:
    length(variables('FinalArray'))

    Then click "Menu" button of Compose 3 action and then click "Configure run after", Within "Compose 3" action should run after panel, we firstly select Set variable 2 action tab, then select is successfull and is skipped option, click "Done" button:16.JPG

    Then we select Scope action tab, select is successful option:17.JPG

     

     

    Image reference:18.JPG

     

    19.JPG

    The flow works successfully as below:20.JPG

     

     

    Within following "Apply to each" action, Input parameter should set to FinalArray variable, the screenshot as below:21.JPG

     

     

     

    Best regards,

    Kris

     

     

     

     

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

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 425

#2
11manish Profile Picture

11manish 323 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 274

Last 30 days Overall leaderboard