Obtaining information from an API in JSON format

I'm currently working on integrating a basic Stock API into JSFiddle.net using the Quandl API:

When I use the current format of ".csv" as shown below, I receive a CSV file. However, if I switch the format to ".json" in my API, how can I retrieve the data and effectively implement it on a website?

I believe I need to utilize a getJSON command, but I am struggling to understand its functionality. Does anyone have guidance on this?

Here's the HTML:

<input type="text" id="symbol">
<button id="getPrice">Get Price!</button>
<div id="result">Stock Market Ticker</div>

JavaScript code:

function getPrice() {
  var symbol = $("#symbol").val();

  var baseurl = "https://www.quandl.com/api/v3/datasets/WIKI/";
  var stock = symbol+".csv";
  var endurl = "column_index=4&rows=1&api_key='8mii36sd1q46uLgSTkLm";
  var url = baseurl+ stock + "?" + endurl;

  $("#result ").html("<a href = '" + url + "' >Hyperlink</a>");
}

$("#getPrice ").click(getPrice);

By querying the stock ticker KORS (.CSV file), I obtain this output: Data Close 1/5/2016 40.72

Answer №1

In response to a question on a programming forum about utilizing a Quandl API, I shared the code snippet below which can be tailored for your JSON:

var mainurl = "https://www.quandl.com/api/v3/datasets/WIKI/";
var endURL = "column_index=4&rows=1&api_key='8mii36sd1q46uLgSTkLm";
var qCode = "GOOG"; // you can choose any code here
var fullURL = mainurl + qCode + ".json?" + endURL; 
var req = new XMLHttpRequest();
req.open("GET", fullURL, true);
req.setRequestHeader("Content-Type", "application/json");
req.onload = function() {
    var dataset = JSON.parse(this.responseText).dataset.data;
    // The {}.dataset.data represents the matrix of data in Quandl
    // This applies to most datasets as far as I am aware ...
    // Next step would be to process the data accordingly
}
req.send();

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

Error: The property 'getClientRects' cannot be read because it is null

I'm brand new to learning about React and I've been attempting to incorporate the example found at: Unfortunately, I've hit a roadblock and can't seem to resolve this pesky error message: TypeError: Cannot read property 'getClient ...

Can you explain the functionality behind the expression "this.method.bind(this)"?

Encountered the code for the first time: var Controller = function($scope){ this._scope = $scope; } Controller.$inject = ['$scope']; Controller.prototype.augmentScope = function() { this._scope.a = { methodA: this.methodA.bind( ...

How can you modify a button in Ionic 2 based on the login status, using a modal to redirect to a different page once authenticated?

I have a button on my main page that is supposed to display 'Log out' when the user is currently logged in, and 'Log in' when there is no active user session. Clicking on the login button opens a modal. After successful login, the user ...

Combining the values of two objects and storing them in a single array

I want to write a program that compares 2 objects based on their properties and values. If the "name" property in both objects matches, I need to push that property and its value to a new object called value3. When value3 is logged, the response should lo ...

Combine functions from two objects that share the same properties into an array for each property

I need help combining the methods from two objects into one, resulting in an array of methods for each property in the parent object: obj1 = {"prop1":"method1","prop2":"method2"} obj2 = {"prop1":"method3","prop2":"method4"} Expected result: obj1 = {"pro ...

Using jq to extract multiple values from nested objects

Currently, I'm utilizing the AWS command-line interface (CLI) and am looking for a way to retrieve the names and states of instances through querying. For instance: instance 1, running instance 2, stopped To achieve this, I am using the following que ...

What is the comparison between actual pixels and text size in Internet Explorer?

Can you determine the actual font size in pixels corresponding to the following text size options in Internet Explorer? Largest Larger Medium Smaller Smallest In a web development project, I am looking to achieve a similar functionality to adjust the te ...

Are you looking to connect with Yahoo Weather, Yahoo GeoPlant, Google Weather, or any other API using JavaScript?

I am looking for a solution to retrieve the current weather data for a specific city using JavaScript. Can anyone recommend an API that would be best for this task? Alternatively, are there any applications that allow you to make an AJAX request to obtain ...

Exploring the world of backgrounds in THREE.js

My objective is to overlay 3D objects onto a panorama. I have successfully positioned the objects with the correct perspective, but now I am seeking a method to incorporate a useBackground shader similar to those found in software like Maya and Max into th ...

technique for removing newline characters from JSON objects in Python3

When I generate a JSON data package using the following code, I notice that an unwanted newline character is added to one of the fields: 'fields': {'time': '31.495\n'} How can I remove this \n? import subprocess, sig ...

Assistance needed with sending JSON data to a PHP server using the POST method

I am attempting to transfer JSON data from an HTML form to a PHP server using the POST method. The issue I am encountering is that my code always ends up in the fail block within the callback function. Despite this, the Firebug console (ctrl+shift+J) does ...

% unable to display on tooltip pie chart in highcharts angular js

https://i.stack.imgur.com/Ccd7h.png The % symbol isn't displaying correctly in the highcharts ageData = { chartConfig: { options: { chart: { type: 'pie', width: 275, height: 220, marginTop: 70 ...

Using an Ajax Post Call to send FormData leads to a Get request instead

Having trouble with sending a simple form via POST method. I load the form content using AJAX: $(function() { var arg = { "operation": "upload", "step": "0" ...

What is the correct way to launch a .exe file with a JSON string as a parameter?

Here is an example showcasing some functionality. Consider the following model structure: public class StartParams { public string ParameterOne { get; set; } public string ParameterTwo { get; set; } public string ParameterThree { get; set; } ...

Creating a fresh JSON structure by utilizing an established one

I have a JSON data that contains sections and rubrics, but I only need the items for a new listing. The new object named 'items' should consist of an array of all the items. The final JSON output should be sorted by the attribute 'name&apos ...

Utilizing asynchronous programming for scenarios where two requests need to be sent, with the response from the first request being required for the second request

I have an async function that looks like this: exports.myFunction = async (req, res, next) => { if (some condition) { next() } try { const results = await axios.get(`https://a-domain.com/url/path`); const info = results.data; c ...

Disappear scrollbar when overlay is activated

How can I hide the scroll bar when an overlay is displayed on my page? .overlay{ display: none; opacity:0.8; background-color:#ccc; position:fixed; width:100%; height:10 ...

"At the beginning of an array in JavaScript, I often encounter the issue of receiving

Here is some code that I created: function get_coordinates(container) { var x; var y; var divs = container.getElementsByTagName('div'); Array.from(divs).forEach(div => { y += div.offsetTop+" "; x += d ...

Having trouble with Laravel 5.5 and ajax file uploads?

I am encountering an issue with Laravel 5.5 while trying to get an ajax file. I can successfully receive the file using $_FILES, but $request->file() is not working as expected. Here is the code in question. Below are the HTML & Ajax elements: <htm ...

How can I achieve super subtle shading effects in three.js?

Is there a way to achieve a very soft and subtle shadow in three.js, similar to the one in this image? https://i.sstatic.net/6B6en.jpg So far, I have only been able to create something like this: https://i.sstatic.net/a3rgD.png Here are my current light ...