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?

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

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

  • 0
    Appian Employee
    in reply to nandhinip

    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.

  • a!fromJson("[{
      ""transId"":9223372036854775807,
      ""submitTimeUTC"":""2019-07-16T14:52:26Z"",
      ""submitTimeLocal"":""2019-07-16T07:52:26"",
      ""transactionOk"":true,
      ""accountType"":""Visa"",
      ""accountNumber"":123456,
      ""settleAmount"":412.97,
      ""product"":"""",
      ""marketType"":[""Business"",""Clothing"",""Child""]
    }]")

    i took the above code as reference. the json text in the above example has 2 double quotes.
    the actual json which i am using has the property with in single double quotes. do i need to add anything here?
Reply
  • a!fromJson("[{
      ""transId"":9223372036854775807,
      ""submitTimeUTC"":""2019-07-16T14:52:26Z"",
      ""submitTimeLocal"":""2019-07-16T07:52:26"",
      ""transactionOk"":true,
      ""accountType"":""Visa"",
      ""accountNumber"":123456,
      ""settleAmount"":412.97,
      ""product"":"""",
      ""marketType"":[""Business"",""Clothing"",""Child""]
    }]")

    i took the above code as reference. the json text in the above example has 2 double quotes.
    the actual json which i am using has the property with in single double quotes. do i need to add anything here?
Children