Skip to main content
July 15, 2022
Question

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

  • July 15, 2022
  • 9 replies
  • 3 views

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?

    9 replies

    peter.lewis
    Employee
    July 15, 2022

    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?

    July 15, 2022

    [
    {
    "description": ".",
    "displayName": ""
    },
    {
    "description": "",
    "displayName": ""
    },
    {
    "description": ".",
    "displayName": ""
    }
    ]

    this is my json. how to assign this to localvariable and access the count and property in foreach.

    peter.lewis
    Employee
    July 15, 2022

    Just use a!fromJson() to convert from a JSON value to an Appian value and then use property + count on the result to get what you need.