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

270
Views
alasql & grouping functions: use Javascript or AlaSQL to create the resulting object?

Below the input data:

[
        {
            "name": "jim",
            "color": "blue",
            "age": "22"
        },
        {
            "name": "Sam",
            "color": "blue",
            "age": "33"
        },
        {
            "name": "eddie",
            "color": "green",
            "age": "77"
        }
]

I would like a resulting object using a single AlaSQL query:

{
        "jim": {
            "color": "blue",
            "age": "22"
        },
        "sam": {
            "color": "blue",
            "age": "33"
        },
        "eddie": {
            "color": "green",
            "age": "77"
        }
}

Is there any way to achieve it one shot with a AlaSQL query ? This would allow to easily find contact info (e.g. data["eddie"].age)

The closest way I found is this:

var res = alasql('SELECT name, ARRAY(_) AS details FROM ? GROUP BY name', [data]);

but I still obtain an array under this format:

[
    {
        "name": "jim",
        "details": [{
            "color": "blue",
            "age": "22"
        }],
    },
    {
        "name": "Sam",
        "details": [{
            "color": "blue",
            "age": "33"
        }],
    },
    {
        "name": "eddie",
        "details": [{
            "color": "green",
            "age": "77"
        }]
    }
]

What would be the fatest and efficient way to achieve the goal ?

about 4 years ago · Juan Pablo Isaza
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!