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

348
Views
Function for importing JSON data into Google Spreadsheets doesnt work when the api contains " | "

I am trying to import JSON data to google sheets using a wikidata API.

However, one of the symbols that are used in this api is the vertical bar: | . It is used as an "and" . For example if I want to import data in BOTH english and greek, then I have to use the " | ".

Example API url: https://www.wikidata.org/w/api.php?action=wbgetentities&props=labels&languages=en|el&format=json&ids=Q192151

enter image description here

Notice the use of the | on the api url between en and el.

I use a custom function named importJSON that can be found here

When i paste the api url WITH the | to import the json data to my google sheet, I get an error:

enter image description here

The error says that is on the line 139 which is this in the script:

var jsondata = UrlFetchApp.fetch(url);

BUT if I DONT contain the " | " in the api url, it works fine:

enter image description here

How can I import the JSON data from the api WITH THE " | " ?

I don't know much from coding so if someone could modify the custom script i linked above, or tell me what should I add to the script to make it work?

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

0

You need to encode the url.

Try this light import json function alternative

function myFunction(url='https://www.wikidata.org/w/api.php?action=wbgetentities&props=labels&languages=en|el&format=json&ids=Q192151') {
  const res = UrlFetchApp.fetch(encodeURI(url));
  Logger.log(res.getContentText())
  const obj = JSON.parse(res.getContentText());
  var result = []
  for (let p in obj.entities['Q192151'].labels) {
    var o = obj.entities['Q192151'].labels[p]
    result.push([o.language,o.value])
  } 
  Logger.log(result)
  return(result)
}

enter image description here

encode

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!