Cannot index property 'displayName' of type String into type List of Variant

I have the below sample json variable.

i want to get the number of values under tags. 

local!Json:{
tags:{
"description": " ",
"displayName": ""
},
{
"description": "",
"displayName": ""
},
{
"description": "",
"displayName": ""
},

},

To achieve this, i have tried using  count(local!Json.tags.displayName). it is throwing the below error.

"Cannot index property 'displayName' of type String into type List of Variant".

How to resolve this?

  Discussion posts and replies are publicly visible

Parents
  • Generally that error means that you are trying to index a field that doesn't exist, so it often occurs when your variable is null or empty for some reason. There are two main ways to address this:

    • Determine why your data isn't returning data for those fields (and whether it is valid or not).
    • If it's valid that your field may not be present in the JSON result, then use the property or index function to use error handling. Here's an example:

    property(
      local!Json.tags,
      "displayName",
      {}
    )

    Some other general suggestions - the expression that you have provided above is neither valid JSON nor a valid Appian expression, so it may be contributing to why you aren't getting the correct result. Also, I don't see why you actually need to count the display name - couldn't you just count the total number of tags there are?

Reply
  • Generally that error means that you are trying to index a field that doesn't exist, so it often occurs when your variable is null or empty for some reason. There are two main ways to address this:

    • Determine why your data isn't returning data for those fields (and whether it is valid or not).
    • If it's valid that your field may not be present in the JSON result, then use the property or index function to use error handling. Here's an example:

    property(
      local!Json.tags,
      "displayName",
      {}
    )

    Some other general suggestions - the expression that you have provided above is neither valid JSON nor a valid Appian expression, so it may be contributing to why you aren't getting the correct result. Also, I don't see why you actually need to count the display name - couldn't you just count the total number of tags there are?

Children