Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
31
rated 0 times [  37] [ 6]  / answers: 1 / hits: 32278  / 9 Years ago, tue, september 29, 2015, 12:00:00

I have the following sample JSON and I would like to get the name of the column like Dribbble, Behance ...



{ 
status: 200,
success: true,
result:
[ { Dribbble: 'a',
Behance: '',
Blog: 'http://blog.invisionapp.com/reimagine-web-design-process/',
Youtube: '',
Vimeo: '' },
{ Dribbble: '',
Behance: '',
Blog: 'http://creative.mailchimp.com/paint-drips/?_ga=1.32574201.612462484.1431430487',
Youtube: '',
Vimeo: '' } ]
}


I'm using Request module and it returns JSON fine but I'm struggling to get the column name in string format. If I could get the column in number format at least, I would be able to know if it's the right column but I get two 0s instead.



request({
url: url,
json: true
}, function (error, response, body) {

if (!error && response.statusCode === 200) {
callback(body)
var json = body.result;

for (var key in json) {
if (json.hasOwnProperty(key)) {
var column = Object.keys(key);
console.log(column[0]);
}
}

}
})

More From » json

 Answers
14
var json = { 
status: 200,
success: true,
result: [
{
Dribbble: 'a',
Behance: '',
Blog: 'http://blog.invisionapp.com/reimagine-web-design-process/',
Youtube: '',
Vimeo: ''
},
{
Dribbble: '',
Behance: '',
Blog: 'http://creative.mailchimp.com/paint-drips/?_ga=1.32574201.612462484.1431430487',
Youtube: '',
Vimeo: '' }
]
}
// get the results (useful data) somewhere
var results = json[result];
// get the first result set, or you can loop trhrough all, assuming that each reuslt set is the same.
if (results.length > 0){
var columnsIn = results[0];
for(var key in columnsIn){
console.log(key); // here is your column name you are looking for
}
}else{
console.log(No columns);
}


This code snippet should point you in the proper direction


[#64894] Saturday, September 26, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yisroels

Total Points: 256
Total Questions: 94
Total Answers: 102

Location: Chad
Member since Mon, Dec 5, 2022
1 Year ago
;