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

178
Views
Separate Id and name in key of JSON

I have data on worker in my database in JSON format. which looks like this

{"45051-Cortador 1 Siloc": "hsgvs", "45063-Nihil impedit quia": "okbbd",}

in this JSON Key contains id and name of user for example in first key 45051 is id and Cortador 1 Siloc is name of user. I want id from key so that I can use it and I want to use it in Laravel Controller(PHP). Thanks,

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use split here

const obj = {
  "45051-Cortador 1 Siloc": "hsgvs",
  "45063-Nihil impedit quia": "okbbd",
};

const result = Object.keys(obj).map((s) => s.split("-"));

console.log(result);

result.forEach(([k, v]) => console.log(k, v));
/* This is not a part of answer. It is just to give the output fill height. So IGNORE IT */
.as-console-wrapper {
  max-height: 100% !important;
  top: 0;
}

over 4 years ago · Santiago Trujillo Report

0

You can use collection

 $result= collect(json_decode($json))->map(function ($item,$key){

        $data=explode("-",$key);

        return ['id'=>$data[0]??null,'name'=>$data[1]??null];
    })->values()
over 4 years ago · Santiago Trujillo 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!