Receiving a getRange error when importing JSON into Google Sheets

Struggling with importing JSON data to Google Spreadsheets using Google Script? I don't have much Java knowledge, so forgive me if this question seems a bit silly! However, I do have experience coding in VBA.

My current challenge involves pulling live exchange rates from a cryptocurrency exchange's API. While I was successful with a different exchange's API, the JSON structure here is slightly different.

The problematic JSON looks like this:

{"success":true,"message":"","result":{"Bid":0.00011437,"Ask":0.00011447,"Last":0.00011447}}
I've verified the JSON on https://jsonlint.com/ and it seems fine.

Here's the code I'm using:

 1 function pullJSON_XRP() {
 2 var ss = SpreadsheetApp.getActiveSpreadsheet();
 3 var sheets = ss.getSheets();
 4 var sheet = ss.getActiveSheet();
 5 Logger.log(sheets)
 6 var url="https://bittrex.com/api/v1.1/public/getticker?market=BTC-XRP"; // JSON call URL 
 7 
 8 var response = UrlFetchApp.fetch(url);
 9 var dataAll = JSON.parse(response.getContentText()); 
10 var dataSet = dataAll;
11 Logger.log(dataSet)
12 var rows = [],
13 data;
14 Logger.log(rows)
15 
16 for (i = 0; i < dataSet.rows; i++) {
17 data = dataSet[i];
18 rows.push(data.result.Bid, data.result.Ask, data.result.Last); //JSON entities
19 }
20 
21 dataRange = sheet.getRange(3, 1, rows.length, 3); // 4th Denotes total number of entites
22 dataRange.setValues(rows);
23 }

I encounter an error at row 21. The error message is still in Swedish despite changing my language settings on Google. It roughly translates to: "Range coordinates or size invalid." Initially, I thought the issue might be due to

dataRange = sheet.getRange(3, 1, rows.length, 3);
not matching the array properly. After numerous attempts and tests, I suspect that my parsed JSON isn't being accessed correctly in
rows.push(data.result.Bid, data.result.Ask, data.result.Last);

Even after trying data.Bid, data.Ask, data.Last, the same error persists.

Your assistance would be highly valued! =)

Thank you for your time and consideration!

Sincerely,

Brian

Answer №1

Here's a straightforward method:

function fetchJSON_XRP() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheets = ss.getSheets();
 var sheet = ss.getActiveSheet();
 var url="https://bittrex.com/api/v1.1/public/getticker?market=BTC-XRP"; // URL for JSON request
 var response = UrlFetchApp.fetch(url);
 var data = JSON.parse(response.getContentText()); 
 var values=[[data.result.Bid, data.result.Ask, data.result.Last]];
 sheet.getRange("A3:C3").setValues(values);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for accessing JSON data from a JSON file in Yii to create a cascading dropdown

How can I use Yii to read data from two JSON files, state.json and city.json, in order to create a dependent dropdown select functionality? State JSON { "states": [{"regionid":122,"countryid":254,"region":"Alabama"}, {"regionid":123,"countryid":254,"regi ...

What is the process for retaining data in mongoose without generating a new database object?

Whenever I try to save data using a bot command, a new object is created every time the data is submitted. I want to ensure that only one object is created, but every time the same user submits data, it should automatically update rather than create a new ...

What is the best way to parse JSON data received from an Android device using PHP?

I am having an issue with my android emulator where it is sending a request to a PHP script to access MySQL data. I have checked the PHP script by manually giving values to the SQL query and I can retrieve the data in my Android emulator. However, I am fac ...

Learning how to parse Json to a controller object for Kendo UI grid server filtering

I've encountered an issue with filtering the Kendo UI grid server-side. When I check the developer tools, I see the following query string: /Home/GetUsmMessage?{"filter":{"logic":"and","filters":[{"field":"MessageId","operator":"eq","value":1}]},"gro ...

Whenever I create the code using javascript, padding seems to always show up

I have a basic stacked row layout that displays an upper box and lower box without any padding. <span id="route" class="small"> <div class="row" style="border-style:solid;"> <div class="col-md-12 col-12"> <p>UpperBox</p& ...

Converting an array of strings into an array of objects in JArray

My goal is to incorporate a JArray into a manually created Jobject and then utilize that JObject for a Put API Call. This is the content of the JArray I have: [ "{\"name\":\"route4\",\"properties&bs ...

Encountered a problem while trying to install using npm install

Encountering an error while running npm install on Ubuntu 12.04: Here is a snippet from my npm-debug.log showing where the errors occur: ... (contents of npm-debug.log) ... This is my package.json: { "name": "www", "version": "0.0.1", /"p ...

Can JavaScript and CSS be used to dynamically style textarea content as it is being typed by the user?

I am wondering if it is possible to apply styling to content in a textarea as a user inputs text. For instance: <textarea>abcdefghijklmnopqrstuvwxyz</textarea> Is there a way to highlight all the vowels in the textarea string above using jav ...

Looking for assistance with embedding content into an iFrame?

Having trouble writing into an iframe, I can locate the iframe but unable to input anything into it. Every time I attempt to write into the iframe, I encounter the following error. <div id="offer_description_field" class="control-group wysihtml5_type d ...

After submitting the form, React checkboxes fail to reset their state

Being a relative newcomer to React, I embarked on creating a skincare app as a project to enhance my understanding. In designing the app, I incorporated a form for product registration which includes checkboxes. My current dilemma revolves around clearing ...

Trying to add a single value to a specific index in a JavaScript array, but it is mistakenly assigning multiple values at once

Currently tackling a matrix algorithm with an early roadblock. The array at hand is: [ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 0, 0, 0 ] ] The goal is to convert it into this: [ [ 0, 0, 0 ], [ 0, 9, 0 ], [ 0, 0, 0 ] ] My plan was to alter the middle value like so ...

What is the best way to transfer an array between different pages?

I'm attempting to transfer an array between pages. page1: session_start(); $input01 = array("img01.png", "img02.png", "img03.png); $_SESSION['input01']=$input01; page2: session_start(); shuffle($input01); Outcome: Warning: shuffle( ...

Have Vue props been set to null?

Currently, I have a component within my vue.js application that looks like this: export default { props: ['forums'], methods: { increment(forum, index) { ForumService.increment(forum) .then(() => { ...

Tips for effectively binding attributes based on conditions in Vue.js

Is it possible to conditionally bind attributes in Vue? Yes, you can achieve this using the v-bind directive: Here is an example: <img :src=" status = true ? 'open.svg' : 'close.svg'"> In Angular, this functionality i ...

Encountering an Issue while Importing JSON Data with mongoimport in MongoDB

Hello there, I've been attempting to import a JSON file into my mongodb collection but am encountering an error. Can someone guide me on how to successfully import this json file? I have tried using both mongodb compass and mongoshell but unfortunatel ...

Deployment to Azure using a .json file extension

We are in the process of deploying an Azure package that includes a static .json file. Although we have successfully tested it in the Azure emulator and locally, we encounter an issue when running it on Azure. The application seems to keep spinning and w ...

Generating a tag filter using elements from a collection of profiles

I have an array of profiles containing various skills. Each profile has its own set of tags to describe their skills. For example: profiles = [ { name: "John", skills: ["react", "javascript"]}, { name: "Jane", skil ...

What is causing the reluctance of my Angular test to accept my custom form validation function?

I'm currently facing an issue with testing an angular component called "FooComponent" using Karma/Jasmine. Snippet of code from foo.component.spec.ts file: describe('FooComponent', () => { let component: FooComponent let fixture ...

Formatting for data sources in Angular Material's mat-table component

Looking for assistance with converting data into Angular Material Mat-Table format. Can someone guide me on transforming this data to be compatible with mat-table dataSource? Check out the sample code here "timelineitems": [ { "1/29/2020": { ...

Transferring properties from React Router to child components on the server side

For my Isomorphic app using React, react-router v3, and material-ui, it's crucial to pass the client's user agent to the theme for server-side rendering. This is necessary for MUI to properly prefix inline styles. Initially, the root component o ...