Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let json =
- [
- {
- "TimeStamp": "2018-10-02T11:30:07.211Z",
- "Value": "109316.4691",
- "Quality": 3
- },
- {
- "TimeStamp": "2018-10-02T11:30:49.811Z",
- "Value": "109312.0255",
- "Quality": 3
- },
- {
- "TimeStamp": "2018-10-02T11:31:04.011Z",
- "Value": "109310.5443",
- "Quality": 3
- },
- {
- "TimeStamp": "2018-10-02T11:31:11.111Z",
- "Value": "109309.8037",
- "Quality": 3
- }
- ];
- let fields = Object.keys(json[0]);
- function replacer(key, value) {
- return value === null ? '' : value;
- }
- let csv = json.map(row => {
- return fields.map(fieldName => {
- return JSON.stringify(row[fieldName], replacer)
- }).join(',')
- });
- csv.unshift(fields.join(',')); // add header column
- console.log(csv.join('\r\n'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement