How to modify this JSON to another JSON with JavaScript?

154
April 26, 2019, at 3:10 PM

help please, I need to transform this json:

{
    "status": "200",
    "message": "OK",
    "data": {
        "id": 531,
        "username": "marybetson",
        "first_name": "mary",
        "last_name": "betson",
        "email": "mary.betson@gmail.com",
        "hits_asigned": 999995,
        "consumed_hits": 0,
        "profile": {
            "id": 441,
            "nombre_perfil": "Documentation",
            "description": null
        },
        "company": {
            "id": 88,
            "plan": {
                "id": 88,
                "nombre_plan": "sell",
                "costo": 1000000000,
                "num_hits": 2147483647,
                "basic_cost": 1,
                "hits": {
                    "id": 91,
                    "geo": 0,
                    "db": 0,
                    "iso": 0
                },
                "id_perfile": 289
            },
            "nombre_empresa": "ventasana",
            "period": "2020-10-04 23:59:59",
            "hits": 2147483647,
            "product_type": 0,
            "contact_person": "Any Hutson",
            "geo": {
                "id": 1,
                "nombre_geo": "standart"
            },
            "country": null
        },
        "db_asigned": [
            {
                "id": 338,
                "nombre_sub_base": "example21",
                "selected_fields": "id,name,last_name",
                "alias_fields": "friend",
                "id_purchase": 403
            },
            {
                "id": 717,
                "nombre_sub_base": "example22",
                "selected_fields": "id,name,last_name",
                "alias_fields": "friend",
                "id_purchase": 403
            }
        ],
        "is_admin": false,
        "products": [
            {
                "description": "Data from db",
                "name": "Datadb",
                "id_module_core": 2,
                "module": [
                    {
                        "description": "Quala",
                        "name": "stone",
                        "id": 6,
                        "alias": "stone",
                        "submodule": [
                            {
                                "description": "example20",
                                "name": "Geo",
                                "id": 20
                            },
                            {
                                "description": "example21",
                                "name": "store",
                                "id": 21
                            }
                        ]
                    }
                ],
            },           
            {
                "descripcion": ":D",
                "nombre": "Demogra",
                "modulo": [],
                "id_module_core": 9
            }
        ]
    }
}

To this Json:

{
    "status": "200",
    "message": "OK",
    "data": {
        "id": 531,
        "username": "marybetson",
        "first_name": "mary",
        "last_name": "betson",
        "email": "mary.betson@gmail.com",
        "hits_asigned": 999995,
        "consumed_hits": 0,
        "profile": {
            "id": 441,
            "nombre_perfil": "Documentation",
            "description": null
        },
        "company": {
            "id": 88,
            "plan": {
                "id": 88,
                "nombre_plan": "sell",
                "costo": 1000000000,
                "num_hits": 2147483647,
                "basic_cost": 1,
                "hits": {
                    "id": 91,
                    "geo": 0,
                    "db": 0,
                    "iso": 0
                },
                "id_perfile": 289
            },
            "nombre_empresa": "ventasana",
            "period": "2020-10-04 23:59:59",
            "hits": 2147483647,
            "product_type": 0,
            "contact_person": "Any Hutson",
            "geo": {
                "id": 1,
                "nombre_geo": "standart"
            },
            "country": null
        },
        "db_asigned": [
            {
                "id": 338,
                "nombre_sub_base": "example21",
                "selected_fields": "id,name,last_name",
                "alias_fields": "friend",
                "id_purchase": 403
            },
            {
                "id": 717,
                "nombre_sub_base": "example22",
                "selected_fields": "id,name,last_name",
                "alias_fields": "friend",
                "id_purchase": 403
            }
        ],
        "is_admin": false,
        "products": [
        {
            "description": "example20",
            "name": "Geo",
            "id": 20,
            "id_father": 2
        },
        {
            "descripcion": "example21",
            "nombre": "store",
            "id": 21,
            "id_father": 2
        }
        ]
    }
}

I have to do the following in '' products '':
1. Remove the main modules and leave the submodules in an array of objects
2. The submudules must contain the "id_father" which is the same "id_module_core"
3. Delete in the object "Demogra" of the array

I have tried to use for-in and Object.values, I would appreciate the help

Rent Charter Buses Company
READ ALSO
issue with set timeinterval in reactjs

issue with set timeinterval in reactjs

I tried to call a function in set time inter val for every 5 seconds but i throws errors in TypeError: thisintialState is not a function

193
How to find a number which is the result of added which elements in the array(Javascript)?

How to find a number which is the result of added which elements in the array(Javascript)?

For example, there is an array arr[1,2,4,8,16,32,64,128], each element represents a permissionThis is the number used for permission assignment

162
keypress being deprecated, how to get the characters typed by a user?

keypress being deprecated, how to get the characters typed by a user?

The javascript keypress event is deprecated: https://developermozilla

209
How do I retrieve survey radio buttons input to the next HTML page? Using local storage and pure javascript

How do I retrieve survey radio buttons input to the next HTML page? Using local storage and pure javascript

I'm trying to create a response page with information of the user from the survey formHowever, I can't retrieve the input for radio buttons

318