I am doing a select query on a DB2 database using NodeJS. The query returns FIRST 5 ROWS.
I want to convert these 5 statement that the query returns into a Json format object. Is there something that is already built that i can reuse to convert query to json ?
var ibmdb = require('ibm_db');
ibmdb.open("DRIVER={DB2};DATABASE=profiledb;HOSTNAME=158.xx.xx.xxx;UID=user;PWD=pass;PORT=1234;PROTOCOL=TCPIP", function (err,conn) {
if (err) return console.log(err);
conn.query('SELECT STMT_TEXT, ESTIMATE FROM TABLEUSUAGE WHERE TIMESTAMP > (SELECT CURRENT DATE - 2 DAY FROM SYS.SYSDUMMY1) ORDER BY ESTIMATE DESC FETCH FIRST 5 ROWS ONLY', function (err, data) {
if (err) console.log(err);
var data_from_query = data;
console.log(data);
conn.close(function () {
console.log('done');
});
});
});
Yes try the below statement that would convert your output to Json format.
console.log(JSON.stringify(data));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With