2

I have a JSON like this,

{
    "Name"          : "Gokul",
    "PhoneNumber"   : 9876543210,
    "Qualification" : "BE"
}

I need to convert it to CSV and the converted CSV should not have JSON keys, I need to convert only JSON values to CSV and my result should be like this,

["Gokul",9876543210,"BE"]

Using Node JS, I need to this Conversion.

2 Answers 2

2

You could install lodash (npm install lodash) and use _.values:

var _ = require('lodash');
var json = { "Name" : "Gokul", "PhoneNumber" : 9876543210, "Qualification" : "BE" };
var values = _.values(json); // It will be ["Gokul",9876543210,"BE"]
Sign up to request clarification or add additional context in comments.

Comments

1
var json = { "Name" : "Gokul", "PhoneNumber" : 9876543210, "Qualification" : "BE" };
var arr = Object.keys(json).map(function(key,index) {
    return json[key];
});
console.log(arr);
//logs [Gokul,9876543210,BE]
console.log(arr.join(','))
//logs Gokul,9876543210,BE

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.