title: How to get an Object without wrapping of square brackets in PostgreSQL using Node.js and express?
body: <p>I'm using PostgreSQL with <a href="https://node-postgres.com/api/pool" rel="nofollow noreferrer">node-postgres: pool</a>, Node.js and express to make some simple queries, I get in return the object wrapped with square brackets but I would like to get it without it.</p>
  
  <p>The employeeDA.js:</p>
  
  <pre><code>const Pool = require("pg").Pool;
  require("dotenv").config();
  
  const pool = new Pool({
    user: process.env.USER,
    host: process.env.HOST,
    database: process.env.DATABASE,
    password: process.env.PASSWORD,
    port: process.env.PORT
  });
  
  const getOneDiet = id =&gt; {
    let p = new Promise((resolve, reject) =&gt; {
      return pool.query(
        `SELECT employee.id, employee.first_name, employee.last_name, array_agg(diet.description) AS diet_list
        FROM employee_diet
          INNER JOIN employee ON employee_diet.employee_id = employee.id
          INNER JOIN diet ON employee_diet.diet_id = diet.id
        WHERE employee.id = ${id}
        GROUP  BY 1`,
        (error, results) =&gt; {
          if (error) {
            console.log(error);
            reject(`ERROR: unable to get count: ${error}`);
          } else {
            resolve(results.rows);
          }
        }
      );
    });
    return p;
  };
  </code></pre>
  
  <p>The conrtoller.js: </p>
  
  <pre><code>  const getEmployeeDiet = async (request, response) =&gt; {
    const id = parseInt(request.params.id);
    try {
      const employeeDiet = await employeeDA.getOneDiet(id);
      console.log(employeeDiet)
      response.status(200).json(employeeDiet);
    } catch (error) {
      console.log(error);
    }
  }
  </code></pre>
  
  <p>The result:</p>
  
  <pre><code>[
       {
        "id": 8,
        "first_name": "obos",
        "last_name": "fomo",
        "diet_list": [
            "vegan",
            "paleo"
        ]
       }
  ]
  </code></pre>
  
  <p>I want the result to be:</p>
  
  <pre><code>{
        "id": 8,
        "first_name": "obos",
        "last_name": "fomo",
        "diet_list": [
            "vegan",
            "paleo"
        ]
  }
  </code></pre>
  
  <p>As suggested <a href="https://stackoverflow.com/questions/39849997/why-sql-returns-an-array-instead-of-an-object/39850570#39850570">here</a> I saw that in SQL Server there's a command to handle this: <code>WITHOUT_ARRAY_WRAPPER</code> is there something similar in PostgreSQL?
  I'm looking for a better solution than <code>resolve(results.rows[0])</code></p>