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

146
Views
almacenar datos eliminando la clave anidada usando el nodo js/javascript

 let json=[ { metadata: { tags: [] }, sys: { space: { sys: [Object] }, id: '4gSSbjCFEorYXqrgDIP2FA', type: 'Entry', }, fields: { richTextEditor: { 'fn-US': [Object] }, short: { 'as-ds': 'hello default value' }, shortUrl: { 'en-US': 'www.google.com' }, shortSlugOption: { 'zh-cht': 'hello-default-value' }, mediaFileAssetLink: { 'ur-pk': [Array] }, mediaFileAssetGalary: { 'en-US': [Array] }, singleMediaImage: { 'cy-az-az': [Object] }, booleanField: { 'en-US': true }, locationField: { 'zh-mo': [Object] }, dateNTime: { 'sv': '2022-02-01T00:00+05:30' } } } ]; json.map((data) => { console.log(data.fields); /* fs.writeFile( "./data.json", JSON.stringify(data.fields, null, 4), (err) => { if (err) throw console.log(err.messages); } ); */ });

Obtuve este objeto y escribí la función de mapa para obtener todos los campos que obtuve de la salida.

Y estoy tratando de almacenar en un archivo JSON pero no quiero almacenar datos en este formato

formato esperado

 richTextEditor: [Object] , short: 'hello default value' , shortUrl: 'www.google.com' , shortSlugOption: 'hello-default-value' , mediaFileAssetLink: [Array] , mediaFileAssetGalary: [Array] , singleMediaImage: [Object] , booleanField: true , locationField: [Object] , dateNTime: '2022-02-01T00:00+05:30'

¿Cómo puedo eliminar todos los anidados 'fn-us', 'as-ds' n all y almacenar el valor en el formato esperado?

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

0

Por ejemplo, puede usar Object.entries y Object.fromEntries() en combinación con .map() para devolver la nueva estructura:

 let json=[ { metadata: { tags: [] }, sys: { space: { sys: [Object] }, id: '4gSSbjCFEorYXqrgDIP2FA', type: 'Entry', }, fields: { richTextEditor: { 'fn-US': [Object] }, short: { 'as-ds': 'hello default value' }, shortUrl: { 'en-US': 'www.google.com' }, shortSlugOption: { 'zh-cht': 'hello-default-value' }, mediaFileAssetLink: { 'ur-pk': [Array] }, mediaFileAssetGalary: { 'en-US': [Array] }, singleMediaImage: { 'cy-az-az': [Object] }, booleanField: { 'en-US': true }, locationField: { 'zh-mo': [Object] }, dateNTime: { 'sv': '2022-02-01T00:00+05:30' } } } ]; const res = json.map((data) => { const fields = Object.fromEntries(Object.entries(data.fields).map(el=>(el[1]=Object.values(el[1])[0], el))) return {...data, fields } /* fs.writeFile( "./data.json", JSON.stringify(data.fields, null, 4), (err) => { if (err) throw console.log(err.messages); } ); */ }); console.log(res);

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!