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

246
Views
¿Cómo analizar llaves JSON en Google Apps Script?

Tengo el siguiente resultado proveniente de una API. ¿Cómo puedo analizar esto usando Google Apps Script y obtener ese resultado como una tabla de Hojas de cálculo de Google?

Intenté lo siguiente, pero solo obtuve Nulls.

 var response = UrlFetchApp.fetch(url, options); var text = response.getContentText(); for (i in text) { Logger.log(text[i]); }
 { "status":1, "complete":1, "list":{ "3357271691":{ "item_id":"3357271691", "resolved_id":"3357271691", "given_url":"https:\/\/www.bloomberg.com\/news\/features\/2021-06-15\/airbnb-spends-millions-making-nightmares-at-live-anywhere-rentals-go-away", "given_title":"", "favorite":"0", "status":"0", "time_added":"1623783338", "time_updated":"1623783338", "time_read":"0", "time_favorited":"0", "sort_id":0, "resolved_title":"Airbnb Is Spending Millions of Dollars to Make Nightmares Go Away", "resolved_url":"https:\/\/www.bloomberg.com\/news\/features\/2021-06-15\/airbnb-spends-millions-making-nightmares-at-live-anywhere-rentals-go-away", "excerpt":"When things go horribly wrong during a stay, the company\u2019s secretive safety team jumps in to soothe guests and hosts, help families\u2014and prevent PR disasters. Megaphone.fm: How Airbnb Makes Nightmares Disappear...", "is_article":"1", "is_index":"0", "has_video":"0", "has_image":"1", "word_count":"155", "lang":"en", "top_image_url":"https:\/\/assets.bwbx.io\/images\/users\/iqjWHBFdfxIU\/iWjqS9z4c46I\/v0\/1200x630.jpg", "domain_metadata":{ "name":"Bloomberg", "logo":"https:\/\/logo.clearbit.com\/bloomberg.com?size=800", "greyscale_logo":"https:\/\/logo.clearbit.com\/bloomberg.com?size=800&greyscale=true" }, "listen_duration_estimate":60 } } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que su objetivo es el siguiente.

  • Desea analizar los valores de text recuperados y colocar los datos en la hoja de cálculo.

En este caso, ¿qué tal el siguiente script de muestra? En este script de muestra, los valores se analizan y crean una matriz bidimensional, y la matriz se coloca en la hoja de cálculo.

Guión de muestra:

 function myFunction() { var response = UrlFetchApp.fetch(url, options); var text = response.getContentText(); // I added below script. var header = ["item_id", "resolved_id", "given_url","given_title","favorite","status","time_added","time_updated","time_read","time_favorited","sort_id", "resolved_title","resolved_url","excerpt","is_article","is_index","has_video","has_image","word_count","lang","top_image_url", "domain_metadata.name","domain_metadata.logo","domain_metadata.greyscale_logo","listen_duration_estimate"]; var values = [header, ...Object.values(JSON.parse(text).list).map(o => header.map(k => { var temp = k.split("."); if (temp.length == 1) { return o[temp[0]] || ""; } return o[temp[0]] && o[temp[0]][temp[1]] ? o[temp[0]][temp[1]] : ""; }))]; console.log(values) // You can check the created array. var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Articles"); // Please set the sheet name. sheet.getRange(1, 1, values.length, values[0].length).setValues(values); }
  • En este caso, todos los valores se colocan en la hoja de cálculo. Entonces, cuando desee cambiar el encabezado, modifíquelo.

Nota:

  • Esta secuencia de comandos de muestra supone que su valor de text es el mismo que el valor que se muestra en su pregunta. Cuando la estructura del valor es diferente, es posible que no se pueda usar este script. Tenga cuidado con esto.

Referencias:

  • mapa()
  • Objeto.valores()
  • establecerValores()
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!