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

85
Views
Cambiar y/o fusionar dos estructuras de objetos JSON

Digamos que nos dan un JSON siguiente:

 { "a": { "title": { "text": "text a" } }, "b": { "title": { "text": "text b" } } }

¿Cómo podría convertir y/o fusionar esto en la siguiente estructura:

 { "title": { "text": { "a": "text a", "b": "text b" } } }

o un ejemplo diferente:

 let aObject = { "level1": { "level2": { "level3": "text a" } } } let bObject = { "level1": { "level2": { "level3": "text b" } } } let cObject = { "level1": { "level2": { "level3": "text c" } } }

dentro

 { "level1": { "level2": { "level3": { "aObject": "text a", "bObject": "text b", "cObject": "text c" } } } }

Puede ser muy fácil ya que me falta una palabra clave que describa esta función, o puede ser complicado archivarlo. Cualquier ayuda es apreciada.

Ejemplo de trabajo, buscando una solución más simple:

 let object = { "a": { "title": { "text": "text a" } }, "b": { "title": { "text": "text b" } } } function reduce(node, object, result = {}) { for (let key in object) { if (typeof result[key] === 'undefined') { result[key] = {} } if (typeof object[key] === 'string') { result[key][node] = object[key] } else { reduce(node, object[key], result[key]) } } return result } let result = Object.entries(object).reduce((result, [key, value]) => { return reduce(key, value, result) }, {}) console.log(result)

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

0

Se puede hacer de esta manera. :)

 let obj = { a: { title: { text: "text a" } }, b: { title: { text: "text b" } } }; let test = {}; test["title"] = {}; test.title["text"] = {}; Object.keys(obj).forEach((key) => { test.title.text[key] = `text ${key}`; }); console.log(test);

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!