Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
How to send json result as a Dictionary instead of Array in expressjs

I want to send response as a dictionary like this:

{
    "id": 5928101,
    "category": "animal welfare",
    "organizer": "Adam",
    "title": "Cat Cabaret",
    "description": "Yay felines!",
    "location": "Meow Town",
    "date": "2019-01-03T21:54:00.000Z",
    "time": "2:00",
}

But I am using bellow code, which results an array

var ress = JSON.stringify(sqlResults)
console.log('response json:' + ress)
res.send(ress)

The resulted array has brackets [] like this:

[
    {
        "id": 5928101,
        "category": "animal welfare",
        "organizer": "Adam",
        "title": "Cat Cabaret",
        "description": "Yay felines!",
        "location": "Meow Town",
        "date": "2019-01-03T21:54:00.000Z",
        "time": "2:00",
    }
]

How can I send result without a third bracket?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you return the first element of your sqlResults array you should get the result you wish.

You should also be able to use res.json(dict) to send your result to the client.

sqlResults = [
    {
        "id": 5928101,
        "category": "animal welfare",
        "organizer": "Adam",
        "title": "Cat Cabaret",
        "description": "Yay felines!",
        "location": "Meow Town",
        "date": "2019-01-03T21:54:00.000Z",
        "time": "2:00",
    }
];

const dict = sqlResults[0];
var ress = JSON.stringify(dict, null, 2)
console.log('response json:' + ress)

// You can then send using res.send(ress);
// Or simply res.json(dict);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!