1

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

1
  • downvote for not even using the documentation behind the link you provided... Commented Jun 4, 2018 at 12:18

1 Answer 1

5

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;
Sign up to request clarification or add additional context in comments.

2 Comments

FYI the default value is now oracledb.OUT_FORMAT_ARRAY instead of oracledb.ARRAY, If specified as oracledb.OUT_FORMAT_OBJECT, each row is fetched as a JavaScript object. The older, equivalent constants oracledb.ARRAY and oracledb.OBJECT are deprecated.
Modified answer to follow current documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.