Reputation: 6512
My DB select result
{
"metaData": [
{
"name": "CUSTOMERID"
},
{
"name": "NAME"
},
{
"name": "EMAILID"
},
{
"name": "PHONE_NUMBER"
},
{
"name": "CREATED_AT"
},
{
"name": "ACC_STATUS"
}
],
"rows": [
[
"62c697be-b0b8-4f90-a014-149c1c175303",
"ratan uday kumar",
"[email protected]",
"+91781891",
"2018-06-04T10:20:55.505Z",
0
]
]
}
Expected Data
[
{
"CUSTOMERID": "62c697be-b0b8-4f90-a014-149c1c175303",
"NAME": "ratan uday kumar",
"EMAILID": "[email protected]",
"PHONE_NUMBER": "+91781891",
"CREATED_AT": "2018-06-04T10:20:55.505Z",
"ACC_STATUS": 0
}
]
I am using nodejs oracledb package
Is there any method to get result in json array or do manually i have to write json array function???
The Answer is by setting the Output format of response to object provided by @torsten link
var oracledb = require('oracledb');
oracledb.outFormat = oracledb.OBJECT;
The above answer have worked for me
Upvotes: 1
Views: 2907
Reputation: 12080
You most probably look for "oracledb.outFormat". Check the documentation of this feature.
3.2.14 oracledb.outFormat
The format of query rows fetched when using connection.execute() or connection.queryStream().
It affects both ResultSet and non-ResultSet queries.
It can be used for top level queries and REF CURSOR output.
This can be either of the Oracledb constants oracledb.OUT_FORMAT_ARRAY or oracledb.OUT_FORMAT_OBJECT. The default value is oracledb.OUT_FORMAT_ARRAY which is more efficient. The older, equivalent constants oracledb.ARRAY and oracledb.OBJECT are deprecated.
Just add one line should already help:
var oracledb = require('oracledb');
oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
Upvotes: 5