Apologies for my inability to find more suitable phrasing for my question.
The scenario is this - I have a nested JSON structure, and for some reason, I need to extract the value of a nested key-value pair object and place it outside the JSON.
JSON example:
DataSource= [
{
"a": 1,
"name": "jack",
"version": 1,
"Id": "39da",
"active": false,
"userId": "jack_user",
"properties": [
{
"id": 7080,
"key": "country",
"value": "in",
},
{
"id": 7081,
"key": "state",
"value": "xyz",
},
]}]
Desired JSON output:
DataSource= [
{
"a": 1,
"name": "jack",
"version": 1,
"Id": "39da",
"active": false,
"userId": "jack_user",
"country": "in"
"properties": [
{
"id": 7080,
"key": "country",
"value": "in",
},
{
"id": 7081,
"key": "state",
"value": "xyz",
},
]}]
Although I can iterate over the entire JSON using the code below, I am struggling to select an object from the Properties array.
for (var i = 0; i < this.DataSource.length; i++) {
var tempDataSource = this.DataSource;
console.log(tempDataSource );