Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda