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

230
Views
Is there a way to find a value by knowing his position in the JSON array?

I'm very bad at coding, so probably this will be the most stupid question possible. I want to find a certain value in a JSON by his position in the array. The problem is that the IDs of the elements aren't sorted but they are 'random' numbers (See the photo). My question is, how can I read a certain value from an element by his position in the array? For example the ID 1001 is in position 0 etc... If I use json['data'][1001][...] i can read separately it but it's difficult to write them using a for cicle.

The JSON is LINK

 function myFunction() {
  
  var response = UrlFetchApp.fetch("http://ddragon.leagueoflegends.com/cdn/"+12.5+".1/data/en_US/item.json");
  var content = response.getContentText();
  var json = JSON.parse(content);
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ITEMS");
  var items = sheet.getActiveRange();
  var itemsPosition = Object.keys(json['data']);
  Logger.log(json['data'][1001]['name']); //works with IDs, I obtain 'Boots'
  Logger.log(json['data'][0]['name']); // doesnt work with position
  Logger.log(json['data'[0]['name']); // doesnt work
}

Photo

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

0

Iterating through obj that came from JSON and retrieving name values

function listallnames() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("Sheet name");
  const obj = JSON.parse("Your string");
  let vo = obj.data.map(o => [o.name]);
  sh.getRange(1,1,vo.length,vo[0].length).setValues(vo):
}
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!