Count value follow group element of JSON string

Hi everybody

i have json with strust like bellow

{
  "count": 12,
  "ListTask": [
    {
      "task": "task1",
      "TaskName": "TaskName1",
    },
    {
      "task": "task2",
      "TaskName": "TaskName1",
    },
    {
      "task": "task1",
      "TaskName": "TaskName2",
    },
    {
      "task": "task1",
      "TaskName": "TaskName2",
    },
    {
      "task": "task2",
      "TaskName": "TaskName2",
    },
    {
      "task": "task1",
      "TaskName": "TaskName3",
    },
    {
      "task": "task2",
      "TaskName": "TaskName3",
    },
    {
      "task": "task3",
      "TaskName": "TaskName3",
    },
    {
      "task": "task1",
      "TaskName": "TaskName4",
    },
    {
      "task": "task2",
      "TaskName": "TaskName4",
    },
    {
      "task": "task3",
      "TaskName": "TaskName4",
    },
    {
      "task": "task4",
      "TaskName": "TaskName4",
    }
  ]
}

now i want to count total task follow TaskName,as example above result is:

TaskName1:2

TaskName2:3

TaskName3:3

TaskName4:4

please tell me how to implement it in outsystems

Thanks

Regard

TungNguyen



Hello Tung,

Could you please tell us how is made your application, like from where are you getting the json and what have you done so far (implemented) to do this?

Did you already have a list? Are you storing this in database? Mobile or web? etc.

Please refer this article when asking questions in the forum

https://link.medium.com/nMwsOcqe6U

Cheers

Eduardo Jauch wrote:

Hello Tung,

Could you please tell us how is made your application, like from where are you getting the json and what have you done so far (implemented) to do this?

Did you already have a list? Are you storing this in database? Mobile or web? etc.

Please refer this article when asking questions in the forum

https://link.medium.com/nMwsOcqe6U

Cheers

Hi Eduardo Jauch

sorry, i have not read rule before create question.

about my question it return from API and need handle to display 

but table record or list record only support entity

i tries handle to convert to structures data but as my describe above i don't know how to count it.


Hi Tung,

I don't think there is a easy way of doing that on Outsystems. 

You can use JSON deserialize and after that loop the list of records while creating a new list with the result. With every record that was on the JSON you need search on the result list of that task name already exist if yes count plus one if not add a new record to the result.

Since the performance of this is really bad for large sets of data you can create an extension and use Linq to query the JSON. Even if this is not an exact solution to your problem you can check how it is done.

Regards,

Marcelo

An additional solution would be to store it in the database, and query it with an Aggregate.