Forum Discussion
Counting objects in an array via JSON
Within a SharePoint list column we are collecting text as an array submitted from a SharePoint page sPFx component (Quick Poll).
I'm hoping to simply collect the amount of responses by counting the number of objects within this array. Alternatively count the occurances of "UserID" in this string.
Seeking support on how to do this within a SharePoint list column via JSON formatting from another column.
'Response' column text (Formatted):
[{
"UserID": "19",
"UserName": "Tom",
"Response": "Yes",
}, {
"UserID": "117",
"UserName": "Richard",
"Response": "No",
}, {
"UserID": "134",
"UserName": "Harry",
"Response": "yes",
}]
Desired outcome in 'Response' column (For corresponding row):
Responses = 3
Darren70s There is no direct function/operator available to count the number of occurrences of substring in given string using JSON formatting.
Even if it is possible using combination of different operators available in JSON formatting, it will be very complex solution. theChrisKent Is there any easy solution available for this?
My recommendation: Use SPFx solution to find the length of array - If you have access to SPFx code which you are using to collect array in text column, you can easily check the length of array & update it in list column.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
1 Reply
Darren70s There is no direct function/operator available to count the number of occurrences of substring in given string using JSON formatting.
Even if it is possible using combination of different operators available in JSON formatting, it will be very complex solution. theChrisKent Is there any easy solution available for this?
My recommendation: Use SPFx solution to find the length of array - If you have access to SPFx code which you are using to collect array in text column, you can easily check the length of array & update it in list column.
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.