How to filter nested json array output using one of the array element values

33 views Asked by At

I have a json here - Returning rows of a search result

"rows": [
                    {
                        "uid": "t091_13213131331",
                        "id": "12414_0214124214",
                        "cells": [
                            {
                                "id": "name",
                                "values": [
                                    {
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    }
                                ]
                            },
                            {
                                "id": "status",
                                "values": [
                                    {
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    }
                                ]
                            },
                            {
                                "id": "date",
                                "values": [
                                    {
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    }
                                ]
                            },
                            {
                                "id": "proj",
                                "values": [
                                    {
                                        "id": "123_121314124",
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    }
                                ]
                            },
                            {
                                "id": "documents",
                                "values": [
                                    {
                                        "id": "123_121314124",
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    },
                                    {
                                        "id": "123_121314122",
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    },
                                    {
                                        "id": "123_12325314124",
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    },
                                    {
                                        "id": "1236_8314124",
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    }
                                ]
                            }
                        ]
                    }
]

Now I have to check the id value that matches the value "status" and if that it matches a certain value, then I have to check the value of values -> value. If that also matches the value I need then I need to return the entire entry (all ids that matches name, status, date - basically that array element of the cells array.)

I am looking for the logic and tried iterating inside the cells array and checking the status but when I tried filtering, the output had only this

                            {
                                "id": "status",
                                "values": [
                                    {
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    }
                                ]
                            }

The response I want -

                            {
                                "id": "name",
                                "values": [
                                    {
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    }
                                ]
                            },
                            {
                                "id": "status",
                                "values": [
                                    {
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    }
                                ]
                            },
                            {
                                "id": "date",
                                "values": [
                                    {
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    }
                                ]
                            },
                            {
                                "id": "proj",
                                "values": [
                                    {
                                        "id": "123_121314124",
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    }
                                ]
                            },
                            {
                                "id": "documents",
                                "values": [
                                    {
                                        "id": "123_121314124",
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    },
                                    {
                                        "id": "123_121314122",
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    },
                                    {
                                        "id": "123_12325314124",
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    },
                                    {
                                        "id": "1236_8314124",
                                        "value": "Some value",
                                        "displaytxt": "Some text"
                                    }
                                ]
                            }
0

There are 0 answers