unable to get the data from dynamic json












1















here below is my json



[{
"_hits": 2.163,
"_type": "data",
"_id": "11138",
"_source": {
"urls": "http://localhost:9618/info?data_id=11138",
"host": "max",
"roll": "11138",
"information": {
"type": "image/jpeg",
"data_id": "11138",
"data_size": 186497,
"creation_utctime": "1494831805258",
},
"subhost": "sample"
},
"_index": "max"
}
];


by using the above i want to store in a variable and want to use that for other purpose. So on button click on im processing the data



<button type="button"(click)="getData()" >get Data</button>

getData(){
this.rows = ;
for (var res in this.info){
var row = {};
for (var key in this.info[res]['_source']){
for (var k in this.info[res]['_source'][key]){
let temp = key + "." + k;
row[temp] = this.info[res]['_source'][key][k];
}
row['_id'] = this.info[res]['_id'];
}
this.rows.push(row);
console.log(this.rows);

}
}


Requrired out put is :



host:"max"
information.creation_utctime: "1494831805258"
information.data_id: "11138"
information.data_size: 186497
information.type: "image/jpeg"
roll:"11138"
subhost:"sample"

urls:"http://localhost:9618/info?data_id=11138"
_id: "11138"


the out put i am getting is :



host.0: "m"
host.1: "a"
host.2: "x"
information.creation_utctime: "1494831805258"
information.data_id: "11138"
information.data_size: 186497
information.type: "image/jpeg"
roll.0: "1"
roll.1: "1"
roll.2: "1"
roll.3: "3"
roll.4: "8"
subhost.0: "s"
subhost.1: "a"
subhost.2: "m"
subhost.3: "p"
subhost.4: "l"
subhost.5: "e"
urls.0: "h"
urls.1: "t"
urls.10: "a"
urls.11: "l"
urls.12: "h"
urls.13: "o"
urls.14: "s"
urls.15: "t"
urls.16: ":"
urls.17: "9"
urls.18: "6"
urls.19: "1"
urls.2: "t"
urls.20: "8"
urls.21: "/"
urls.22: "i"
urls.23: "n"
urls.24: "f"
urls.25: "o"
urls.26: "?"
urls.27: "d"
urls.28: "a"
urls.29: "t"
urls.3: "p"
urls.30: "a"
urls.31: "_"
urls.32: "i"
urls.33: "d"
urls.34: "="
urls.35: "1"
urls.36: "1"
urls.37: "1"
urls.38: "3"
urls.39: "8"
urls.4: ":"
urls.5: "/"
urls.6: "/"
urls.7: "l"
urls.8: "o"
urls.9: "c"
_id: "11138"


below is my stackblitzurl



https://stackblitz.com/edit/angular-d7mnpz



so here i want the data the in above require output and i am getting the above output










share|improve this question

























  • You don't need the second for loop.

    – Ibu
    Nov 13 '18 at 18:17











  • @lbu Ok but I want the output as the required out put for that purpose it is important to right

    – Dexter
    Nov 13 '18 at 18:29
















1















here below is my json



[{
"_hits": 2.163,
"_type": "data",
"_id": "11138",
"_source": {
"urls": "http://localhost:9618/info?data_id=11138",
"host": "max",
"roll": "11138",
"information": {
"type": "image/jpeg",
"data_id": "11138",
"data_size": 186497,
"creation_utctime": "1494831805258",
},
"subhost": "sample"
},
"_index": "max"
}
];


by using the above i want to store in a variable and want to use that for other purpose. So on button click on im processing the data



<button type="button"(click)="getData()" >get Data</button>

getData(){
this.rows = ;
for (var res in this.info){
var row = {};
for (var key in this.info[res]['_source']){
for (var k in this.info[res]['_source'][key]){
let temp = key + "." + k;
row[temp] = this.info[res]['_source'][key][k];
}
row['_id'] = this.info[res]['_id'];
}
this.rows.push(row);
console.log(this.rows);

}
}


Requrired out put is :



host:"max"
information.creation_utctime: "1494831805258"
information.data_id: "11138"
information.data_size: 186497
information.type: "image/jpeg"
roll:"11138"
subhost:"sample"

urls:"http://localhost:9618/info?data_id=11138"
_id: "11138"


the out put i am getting is :



host.0: "m"
host.1: "a"
host.2: "x"
information.creation_utctime: "1494831805258"
information.data_id: "11138"
information.data_size: 186497
information.type: "image/jpeg"
roll.0: "1"
roll.1: "1"
roll.2: "1"
roll.3: "3"
roll.4: "8"
subhost.0: "s"
subhost.1: "a"
subhost.2: "m"
subhost.3: "p"
subhost.4: "l"
subhost.5: "e"
urls.0: "h"
urls.1: "t"
urls.10: "a"
urls.11: "l"
urls.12: "h"
urls.13: "o"
urls.14: "s"
urls.15: "t"
urls.16: ":"
urls.17: "9"
urls.18: "6"
urls.19: "1"
urls.2: "t"
urls.20: "8"
urls.21: "/"
urls.22: "i"
urls.23: "n"
urls.24: "f"
urls.25: "o"
urls.26: "?"
urls.27: "d"
urls.28: "a"
urls.29: "t"
urls.3: "p"
urls.30: "a"
urls.31: "_"
urls.32: "i"
urls.33: "d"
urls.34: "="
urls.35: "1"
urls.36: "1"
urls.37: "1"
urls.38: "3"
urls.39: "8"
urls.4: ":"
urls.5: "/"
urls.6: "/"
urls.7: "l"
urls.8: "o"
urls.9: "c"
_id: "11138"


below is my stackblitzurl



https://stackblitz.com/edit/angular-d7mnpz



so here i want the data the in above require output and i am getting the above output










share|improve this question

























  • You don't need the second for loop.

    – Ibu
    Nov 13 '18 at 18:17











  • @lbu Ok but I want the output as the required out put for that purpose it is important to right

    – Dexter
    Nov 13 '18 at 18:29














1












1








1








here below is my json



[{
"_hits": 2.163,
"_type": "data",
"_id": "11138",
"_source": {
"urls": "http://localhost:9618/info?data_id=11138",
"host": "max",
"roll": "11138",
"information": {
"type": "image/jpeg",
"data_id": "11138",
"data_size": 186497,
"creation_utctime": "1494831805258",
},
"subhost": "sample"
},
"_index": "max"
}
];


by using the above i want to store in a variable and want to use that for other purpose. So on button click on im processing the data



<button type="button"(click)="getData()" >get Data</button>

getData(){
this.rows = ;
for (var res in this.info){
var row = {};
for (var key in this.info[res]['_source']){
for (var k in this.info[res]['_source'][key]){
let temp = key + "." + k;
row[temp] = this.info[res]['_source'][key][k];
}
row['_id'] = this.info[res]['_id'];
}
this.rows.push(row);
console.log(this.rows);

}
}


Requrired out put is :



host:"max"
information.creation_utctime: "1494831805258"
information.data_id: "11138"
information.data_size: 186497
information.type: "image/jpeg"
roll:"11138"
subhost:"sample"

urls:"http://localhost:9618/info?data_id=11138"
_id: "11138"


the out put i am getting is :



host.0: "m"
host.1: "a"
host.2: "x"
information.creation_utctime: "1494831805258"
information.data_id: "11138"
information.data_size: 186497
information.type: "image/jpeg"
roll.0: "1"
roll.1: "1"
roll.2: "1"
roll.3: "3"
roll.4: "8"
subhost.0: "s"
subhost.1: "a"
subhost.2: "m"
subhost.3: "p"
subhost.4: "l"
subhost.5: "e"
urls.0: "h"
urls.1: "t"
urls.10: "a"
urls.11: "l"
urls.12: "h"
urls.13: "o"
urls.14: "s"
urls.15: "t"
urls.16: ":"
urls.17: "9"
urls.18: "6"
urls.19: "1"
urls.2: "t"
urls.20: "8"
urls.21: "/"
urls.22: "i"
urls.23: "n"
urls.24: "f"
urls.25: "o"
urls.26: "?"
urls.27: "d"
urls.28: "a"
urls.29: "t"
urls.3: "p"
urls.30: "a"
urls.31: "_"
urls.32: "i"
urls.33: "d"
urls.34: "="
urls.35: "1"
urls.36: "1"
urls.37: "1"
urls.38: "3"
urls.39: "8"
urls.4: ":"
urls.5: "/"
urls.6: "/"
urls.7: "l"
urls.8: "o"
urls.9: "c"
_id: "11138"


below is my stackblitzurl



https://stackblitz.com/edit/angular-d7mnpz



so here i want the data the in above require output and i am getting the above output










share|improve this question
















here below is my json



[{
"_hits": 2.163,
"_type": "data",
"_id": "11138",
"_source": {
"urls": "http://localhost:9618/info?data_id=11138",
"host": "max",
"roll": "11138",
"information": {
"type": "image/jpeg",
"data_id": "11138",
"data_size": 186497,
"creation_utctime": "1494831805258",
},
"subhost": "sample"
},
"_index": "max"
}
];


by using the above i want to store in a variable and want to use that for other purpose. So on button click on im processing the data



<button type="button"(click)="getData()" >get Data</button>

getData(){
this.rows = ;
for (var res in this.info){
var row = {};
for (var key in this.info[res]['_source']){
for (var k in this.info[res]['_source'][key]){
let temp = key + "." + k;
row[temp] = this.info[res]['_source'][key][k];
}
row['_id'] = this.info[res]['_id'];
}
this.rows.push(row);
console.log(this.rows);

}
}


Requrired out put is :



host:"max"
information.creation_utctime: "1494831805258"
information.data_id: "11138"
information.data_size: 186497
information.type: "image/jpeg"
roll:"11138"
subhost:"sample"

urls:"http://localhost:9618/info?data_id=11138"
_id: "11138"


the out put i am getting is :



host.0: "m"
host.1: "a"
host.2: "x"
information.creation_utctime: "1494831805258"
information.data_id: "11138"
information.data_size: 186497
information.type: "image/jpeg"
roll.0: "1"
roll.1: "1"
roll.2: "1"
roll.3: "3"
roll.4: "8"
subhost.0: "s"
subhost.1: "a"
subhost.2: "m"
subhost.3: "p"
subhost.4: "l"
subhost.5: "e"
urls.0: "h"
urls.1: "t"
urls.10: "a"
urls.11: "l"
urls.12: "h"
urls.13: "o"
urls.14: "s"
urls.15: "t"
urls.16: ":"
urls.17: "9"
urls.18: "6"
urls.19: "1"
urls.2: "t"
urls.20: "8"
urls.21: "/"
urls.22: "i"
urls.23: "n"
urls.24: "f"
urls.25: "o"
urls.26: "?"
urls.27: "d"
urls.28: "a"
urls.29: "t"
urls.3: "p"
urls.30: "a"
urls.31: "_"
urls.32: "i"
urls.33: "d"
urls.34: "="
urls.35: "1"
urls.36: "1"
urls.37: "1"
urls.38: "3"
urls.39: "8"
urls.4: ":"
urls.5: "/"
urls.6: "/"
urls.7: "l"
urls.8: "o"
urls.9: "c"
_id: "11138"


below is my stackblitzurl



https://stackblitz.com/edit/angular-d7mnpz



so here i want the data the in above require output and i am getting the above output







javascript json angular






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 18:01







Dexter

















asked Nov 13 '18 at 17:47









DexterDexter

8110




8110













  • You don't need the second for loop.

    – Ibu
    Nov 13 '18 at 18:17











  • @lbu Ok but I want the output as the required out put for that purpose it is important to right

    – Dexter
    Nov 13 '18 at 18:29



















  • You don't need the second for loop.

    – Ibu
    Nov 13 '18 at 18:17











  • @lbu Ok but I want the output as the required out put for that purpose it is important to right

    – Dexter
    Nov 13 '18 at 18:29

















You don't need the second for loop.

– Ibu
Nov 13 '18 at 18:17





You don't need the second for loop.

– Ibu
Nov 13 '18 at 18:17













@lbu Ok but I want the output as the required out put for that purpose it is important to right

– Dexter
Nov 13 '18 at 18:29





@lbu Ok but I want the output as the required out put for that purpose it is important to right

– Dexter
Nov 13 '18 at 18:29












2 Answers
2






active

oldest

votes


















1














Try this:



getData(){
this.rows = ;

const nodeToFlat = '_source';

this.info.forEach( (info,index) => {
let tmpRowStr = {};
for( let x in info[nodeToFlat]){
if(info[nodeToFlat][x].constructor === Object){
for (let z in info[nodeToFlat][x] ) {
tmpRowStr[`${x}.${z}`] = info[nodeToFlat][x][z];
}

} else {
tmpRowStr[`${x}`] = info[nodeToFlat][x];
}
}

this.rows.push(tmpRowStr);
}
)

console.log('======>' ,this.rows);


}


enter image description here






share|improve this answer
























  • but ur getting duplicates rights

    – Dexter
    Nov 14 '18 at 2:03











  • No, i just added another JSON to this.info to show it works with many elements

    – Gabriel Lopez
    Nov 14 '18 at 2:19











  • Ok let me check and get back to you & instead of template literals can we use another i mean $x & $z

    – Dexter
    Nov 14 '18 at 3:02













  • Something like [x,z].join('.') instead of ${x}.${z} ? I think template literals are better

    – Gabriel Lopez
    Nov 14 '18 at 3:23











  • ok could u make such modification as an alternative approach

    – Dexter
    Nov 14 '18 at 4:22



















1














Your getData() is puting the '.k' in the name of the attribute.

You have to do only if it's an object.

Here's the correct code:



    getData() {
this.rows = ;
for (var res in this.info) {
var row = {};
for (var key in this.info[res]['_source']) {
if (typeof this.info[res]['_source'][key] === 'object') {
for (var k in this.info[res]['_source'][key]) {
let temp = key + "." + k;
row[temp] = this.info[res]['_source'][key][k];
}
} else {
row[key] = this.info[res]['_source'][key]
}
row['_id'] = this.info[res]['_id'];
}
}
this.rows.push(row);
console.log(this.rows);
}





share|improve this answer


























  • But if want the required out put it is important right I mean I want the data in that particular required out put format

    – Dexter
    Nov 13 '18 at 18:27











  • I want output like this host:"max" information.creation_utctime: "1494831805258" information.data_id: "11138" information.data_size: 186497 information.type: "image/jpeg" roll:"11138" subhost:"sample" urls:"localhost:9618/info?data_id=11138" _id: "11138"

    – Dexter
    Nov 13 '18 at 18:33











  • Just edited my answer. Try it out to see if that's what you want.

    – Gabriel
    Nov 13 '18 at 18:39











  • ur solution is ok but it is working only for if i pass single json object if i pass more than 1 json object it is not working

    – Dexter
    Nov 14 '18 at 2:04











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286796%2funable-to-get-the-data-from-dynamic-json%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Try this:



getData(){
this.rows = ;

const nodeToFlat = '_source';

this.info.forEach( (info,index) => {
let tmpRowStr = {};
for( let x in info[nodeToFlat]){
if(info[nodeToFlat][x].constructor === Object){
for (let z in info[nodeToFlat][x] ) {
tmpRowStr[`${x}.${z}`] = info[nodeToFlat][x][z];
}

} else {
tmpRowStr[`${x}`] = info[nodeToFlat][x];
}
}

this.rows.push(tmpRowStr);
}
)

console.log('======>' ,this.rows);


}


enter image description here






share|improve this answer
























  • but ur getting duplicates rights

    – Dexter
    Nov 14 '18 at 2:03











  • No, i just added another JSON to this.info to show it works with many elements

    – Gabriel Lopez
    Nov 14 '18 at 2:19











  • Ok let me check and get back to you & instead of template literals can we use another i mean $x & $z

    – Dexter
    Nov 14 '18 at 3:02













  • Something like [x,z].join('.') instead of ${x}.${z} ? I think template literals are better

    – Gabriel Lopez
    Nov 14 '18 at 3:23











  • ok could u make such modification as an alternative approach

    – Dexter
    Nov 14 '18 at 4:22
















1














Try this:



getData(){
this.rows = ;

const nodeToFlat = '_source';

this.info.forEach( (info,index) => {
let tmpRowStr = {};
for( let x in info[nodeToFlat]){
if(info[nodeToFlat][x].constructor === Object){
for (let z in info[nodeToFlat][x] ) {
tmpRowStr[`${x}.${z}`] = info[nodeToFlat][x][z];
}

} else {
tmpRowStr[`${x}`] = info[nodeToFlat][x];
}
}

this.rows.push(tmpRowStr);
}
)

console.log('======>' ,this.rows);


}


enter image description here






share|improve this answer
























  • but ur getting duplicates rights

    – Dexter
    Nov 14 '18 at 2:03











  • No, i just added another JSON to this.info to show it works with many elements

    – Gabriel Lopez
    Nov 14 '18 at 2:19











  • Ok let me check and get back to you & instead of template literals can we use another i mean $x & $z

    – Dexter
    Nov 14 '18 at 3:02













  • Something like [x,z].join('.') instead of ${x}.${z} ? I think template literals are better

    – Gabriel Lopez
    Nov 14 '18 at 3:23











  • ok could u make such modification as an alternative approach

    – Dexter
    Nov 14 '18 at 4:22














1












1








1







Try this:



getData(){
this.rows = ;

const nodeToFlat = '_source';

this.info.forEach( (info,index) => {
let tmpRowStr = {};
for( let x in info[nodeToFlat]){
if(info[nodeToFlat][x].constructor === Object){
for (let z in info[nodeToFlat][x] ) {
tmpRowStr[`${x}.${z}`] = info[nodeToFlat][x][z];
}

} else {
tmpRowStr[`${x}`] = info[nodeToFlat][x];
}
}

this.rows.push(tmpRowStr);
}
)

console.log('======>' ,this.rows);


}


enter image description here






share|improve this answer













Try this:



getData(){
this.rows = ;

const nodeToFlat = '_source';

this.info.forEach( (info,index) => {
let tmpRowStr = {};
for( let x in info[nodeToFlat]){
if(info[nodeToFlat][x].constructor === Object){
for (let z in info[nodeToFlat][x] ) {
tmpRowStr[`${x}.${z}`] = info[nodeToFlat][x][z];
}

} else {
tmpRowStr[`${x}`] = info[nodeToFlat][x];
}
}

this.rows.push(tmpRowStr);
}
)

console.log('======>' ,this.rows);


}


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 18:37









Gabriel LopezGabriel Lopez

2827




2827













  • but ur getting duplicates rights

    – Dexter
    Nov 14 '18 at 2:03











  • No, i just added another JSON to this.info to show it works with many elements

    – Gabriel Lopez
    Nov 14 '18 at 2:19











  • Ok let me check and get back to you & instead of template literals can we use another i mean $x & $z

    – Dexter
    Nov 14 '18 at 3:02













  • Something like [x,z].join('.') instead of ${x}.${z} ? I think template literals are better

    – Gabriel Lopez
    Nov 14 '18 at 3:23











  • ok could u make such modification as an alternative approach

    – Dexter
    Nov 14 '18 at 4:22



















  • but ur getting duplicates rights

    – Dexter
    Nov 14 '18 at 2:03











  • No, i just added another JSON to this.info to show it works with many elements

    – Gabriel Lopez
    Nov 14 '18 at 2:19











  • Ok let me check and get back to you & instead of template literals can we use another i mean $x & $z

    – Dexter
    Nov 14 '18 at 3:02













  • Something like [x,z].join('.') instead of ${x}.${z} ? I think template literals are better

    – Gabriel Lopez
    Nov 14 '18 at 3:23











  • ok could u make such modification as an alternative approach

    – Dexter
    Nov 14 '18 at 4:22

















but ur getting duplicates rights

– Dexter
Nov 14 '18 at 2:03





but ur getting duplicates rights

– Dexter
Nov 14 '18 at 2:03













No, i just added another JSON to this.info to show it works with many elements

– Gabriel Lopez
Nov 14 '18 at 2:19





No, i just added another JSON to this.info to show it works with many elements

– Gabriel Lopez
Nov 14 '18 at 2:19













Ok let me check and get back to you & instead of template literals can we use another i mean $x & $z

– Dexter
Nov 14 '18 at 3:02







Ok let me check and get back to you & instead of template literals can we use another i mean $x & $z

– Dexter
Nov 14 '18 at 3:02















Something like [x,z].join('.') instead of ${x}.${z} ? I think template literals are better

– Gabriel Lopez
Nov 14 '18 at 3:23





Something like [x,z].join('.') instead of ${x}.${z} ? I think template literals are better

– Gabriel Lopez
Nov 14 '18 at 3:23













ok could u make such modification as an alternative approach

– Dexter
Nov 14 '18 at 4:22





ok could u make such modification as an alternative approach

– Dexter
Nov 14 '18 at 4:22













1














Your getData() is puting the '.k' in the name of the attribute.

You have to do only if it's an object.

Here's the correct code:



    getData() {
this.rows = ;
for (var res in this.info) {
var row = {};
for (var key in this.info[res]['_source']) {
if (typeof this.info[res]['_source'][key] === 'object') {
for (var k in this.info[res]['_source'][key]) {
let temp = key + "." + k;
row[temp] = this.info[res]['_source'][key][k];
}
} else {
row[key] = this.info[res]['_source'][key]
}
row['_id'] = this.info[res]['_id'];
}
}
this.rows.push(row);
console.log(this.rows);
}





share|improve this answer


























  • But if want the required out put it is important right I mean I want the data in that particular required out put format

    – Dexter
    Nov 13 '18 at 18:27











  • I want output like this host:"max" information.creation_utctime: "1494831805258" information.data_id: "11138" information.data_size: 186497 information.type: "image/jpeg" roll:"11138" subhost:"sample" urls:"localhost:9618/info?data_id=11138" _id: "11138"

    – Dexter
    Nov 13 '18 at 18:33











  • Just edited my answer. Try it out to see if that's what you want.

    – Gabriel
    Nov 13 '18 at 18:39











  • ur solution is ok but it is working only for if i pass single json object if i pass more than 1 json object it is not working

    – Dexter
    Nov 14 '18 at 2:04
















1














Your getData() is puting the '.k' in the name of the attribute.

You have to do only if it's an object.

Here's the correct code:



    getData() {
this.rows = ;
for (var res in this.info) {
var row = {};
for (var key in this.info[res]['_source']) {
if (typeof this.info[res]['_source'][key] === 'object') {
for (var k in this.info[res]['_source'][key]) {
let temp = key + "." + k;
row[temp] = this.info[res]['_source'][key][k];
}
} else {
row[key] = this.info[res]['_source'][key]
}
row['_id'] = this.info[res]['_id'];
}
}
this.rows.push(row);
console.log(this.rows);
}





share|improve this answer


























  • But if want the required out put it is important right I mean I want the data in that particular required out put format

    – Dexter
    Nov 13 '18 at 18:27











  • I want output like this host:"max" information.creation_utctime: "1494831805258" information.data_id: "11138" information.data_size: 186497 information.type: "image/jpeg" roll:"11138" subhost:"sample" urls:"localhost:9618/info?data_id=11138" _id: "11138"

    – Dexter
    Nov 13 '18 at 18:33











  • Just edited my answer. Try it out to see if that's what you want.

    – Gabriel
    Nov 13 '18 at 18:39











  • ur solution is ok but it is working only for if i pass single json object if i pass more than 1 json object it is not working

    – Dexter
    Nov 14 '18 at 2:04














1












1








1







Your getData() is puting the '.k' in the name of the attribute.

You have to do only if it's an object.

Here's the correct code:



    getData() {
this.rows = ;
for (var res in this.info) {
var row = {};
for (var key in this.info[res]['_source']) {
if (typeof this.info[res]['_source'][key] === 'object') {
for (var k in this.info[res]['_source'][key]) {
let temp = key + "." + k;
row[temp] = this.info[res]['_source'][key][k];
}
} else {
row[key] = this.info[res]['_source'][key]
}
row['_id'] = this.info[res]['_id'];
}
}
this.rows.push(row);
console.log(this.rows);
}





share|improve this answer















Your getData() is puting the '.k' in the name of the attribute.

You have to do only if it's an object.

Here's the correct code:



    getData() {
this.rows = ;
for (var res in this.info) {
var row = {};
for (var key in this.info[res]['_source']) {
if (typeof this.info[res]['_source'][key] === 'object') {
for (var k in this.info[res]['_source'][key]) {
let temp = key + "." + k;
row[temp] = this.info[res]['_source'][key][k];
}
} else {
row[key] = this.info[res]['_source'][key]
}
row['_id'] = this.info[res]['_id'];
}
}
this.rows.push(row);
console.log(this.rows);
}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 13 '18 at 18:38

























answered Nov 13 '18 at 18:17









GabrielGabriel

12117




12117













  • But if want the required out put it is important right I mean I want the data in that particular required out put format

    – Dexter
    Nov 13 '18 at 18:27











  • I want output like this host:"max" information.creation_utctime: "1494831805258" information.data_id: "11138" information.data_size: 186497 information.type: "image/jpeg" roll:"11138" subhost:"sample" urls:"localhost:9618/info?data_id=11138" _id: "11138"

    – Dexter
    Nov 13 '18 at 18:33











  • Just edited my answer. Try it out to see if that's what you want.

    – Gabriel
    Nov 13 '18 at 18:39











  • ur solution is ok but it is working only for if i pass single json object if i pass more than 1 json object it is not working

    – Dexter
    Nov 14 '18 at 2:04



















  • But if want the required out put it is important right I mean I want the data in that particular required out put format

    – Dexter
    Nov 13 '18 at 18:27











  • I want output like this host:"max" information.creation_utctime: "1494831805258" information.data_id: "11138" information.data_size: 186497 information.type: "image/jpeg" roll:"11138" subhost:"sample" urls:"localhost:9618/info?data_id=11138" _id: "11138"

    – Dexter
    Nov 13 '18 at 18:33











  • Just edited my answer. Try it out to see if that's what you want.

    – Gabriel
    Nov 13 '18 at 18:39











  • ur solution is ok but it is working only for if i pass single json object if i pass more than 1 json object it is not working

    – Dexter
    Nov 14 '18 at 2:04

















But if want the required out put it is important right I mean I want the data in that particular required out put format

– Dexter
Nov 13 '18 at 18:27





But if want the required out put it is important right I mean I want the data in that particular required out put format

– Dexter
Nov 13 '18 at 18:27













I want output like this host:"max" information.creation_utctime: "1494831805258" information.data_id: "11138" information.data_size: 186497 information.type: "image/jpeg" roll:"11138" subhost:"sample" urls:"localhost:9618/info?data_id=11138" _id: "11138"

– Dexter
Nov 13 '18 at 18:33





I want output like this host:"max" information.creation_utctime: "1494831805258" information.data_id: "11138" information.data_size: 186497 information.type: "image/jpeg" roll:"11138" subhost:"sample" urls:"localhost:9618/info?data_id=11138" _id: "11138"

– Dexter
Nov 13 '18 at 18:33













Just edited my answer. Try it out to see if that's what you want.

– Gabriel
Nov 13 '18 at 18:39





Just edited my answer. Try it out to see if that's what you want.

– Gabriel
Nov 13 '18 at 18:39













ur solution is ok but it is working only for if i pass single json object if i pass more than 1 json object it is not working

– Dexter
Nov 14 '18 at 2:04





ur solution is ok but it is working only for if i pass single json object if i pass more than 1 json object it is not working

– Dexter
Nov 14 '18 at 2:04


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286796%2funable-to-get-the-data-from-dynamic-json%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Coverage of Google Street View

Full-time equivalent

Surfing