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
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:
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.
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?
While working with Appian expressions, you might see a different number of double quotes because the expression editor will not consider the code as plain text rather it will consider it as an expression. A better way to understand this is - Create a variable of type text and then use it inside a!fromJson() function. Now you can pass your JSON as a test value in the variable.
pls share some samples
Sure, here's an example of what Harshit is saying - if you use a rule input and provide the full JSON in the input, it will ensure that the quotations are set up correctly.
count( property( property( a!fromJson(ri!json), "tags", {} ), "description", {} ) )
Thanks for the response. This will be helpful.