Save the property of a JSON in a Node.js variable

0

I have this JSON

    {
    "user": "user0001",
    "pass": "pass0001",
    "toke": "asdqwe1234",
    "json":[{
    "Notification": [{
            "Channel": 1,
            "Type": 1,
            "Means": [{
                "Number": 88888888,
                "Code": 506
            }],
            "Contents": {
                "Message": "This is a message"
            }
        },
          {
            "Channel": 1,
            "Type": 2,
            "Means": [{
                "Number": 88888888,
                "Code": 506
            }],
            "Contents": {
                "Message": "This is a message"
            }
        }
]
},
{
    "Notification": [{
            "Channel": 2,
            "Type": 1,
            "Means": [{
                "Mail": "[email protected]",
                "Copy": "[email protected]",
                "ccd": "[email protected]"
            }],
            "Contents": {
                "Message": "This is a message",
                "Image": "URL",
                "File": "URL"
            }
        },
        {
            "Channel": 2,
            "Type": 1,
            "Means": [{
                "Mail": "[email protected]",
                "Copy": "[email protected]",
                "ccd": "[email protected]"
            }],
            "Contents": {
                "Message": "This is a message",
                "Image": "URL",
                "File": "URL"
            }
        }
    ]
}
]
}

And I would like to save the property "json" in a variable something like this:

    var jsonFile = [{
    "Notification": [{
            "Channel": 1,
            "Type": 1,
            "Means": [{
                "Number": 88888888,
                "Code": 506
            }],
            "Contents": {
                "Message": "This is a message"
            }
        },
          {
            "Channel": 1,
            "Type": 2,
            "Means": [{
                "Number": 88888888,
                "Code": 506
            }],
            "Contents": {
                "Message": "This is a message"
            }
        }
]
},
{
    "Notification": [{
            "Channel": 2,
            "Type": 1,
            "Means": [{
                "Mail": "[email protected]",
                "Copy": "[email protected]",
                "ccd": "[email protected]"
            }],
            "Contents": {
                "Message": "This is a message",
                "Image": "URL",
                "File": "URL"
            }
        },
        {
            "Channel": 2,
            "Type": 1,
            "Means": [{
                "Mail": "[email protected]",
                "Copy": "[email protected]",
                "ccd": "[email protected]"
            }],
            "Contents": {
                "Message": "This is a message",
                "Image": "URL",
                "File": "URL"
            }
        }
    ]
}
]
    
asked by java005 24.09.2018 в 18:37
source

1 answer

2

You can do the following:

var jsonOriginal = {
    "user": "user0001",
    "pass": "pass0001",
    "toke": "asdqwe1234",
    "json":[{
    "Notification": [{
            "Channel": 1,
            "Type": 1,
            "Means": [{
                "Number": 88888888,
                "Code": 506
            }],
            "Contents": {
                "Message": "This is a message"
            }
        }
]
}]
};

var jsonFile = jsonOriginal.json[0]; // 0 es la prosición en la que se encuentra "Notification". 

console.log(jsonFile);

Greetings!

    
answered by 24.09.2018 / 18:42
source