What is the best way to convert JSON data into a string array and showcase the results?

Recently, I've been exploring the fetch API to retrieve some data. After successfully fetching the data and displaying the response using console log, I now face a challenge in utilizing this information. The API provides me with "result", "id", and "total" fields. I am seeking assistance on how I can convert this data into a string array and effectively leverage the insights offered by the API.

I attempted various approaches, including JSON.Parse, but struggled to convert the JSON data into a string array.

Here is the function where I aim to handle the fetched data for further processing:

function addPost(e){
      e.preventDefault();

      let itemname = document.getElementById('itemname').value;
      let body = document.getElementById('body').value;

      fetch('https://cors-anywhere.herokuapp.com/https://www.pathofexile.com/api/trade/search/Standard', {
        method:'POST',

        headers: {
          'Accept': 'application/json, text/plain, */*',
          'Content-type':'application/json'
        },
        body: JSON.stringify({"query": {"status": {"option": "online"}, "name":itemname, "stats": [{"type": "and", "filters": []}]},"sort": {"price": "asc"}})
      })
      .then((res) => res.json())
      .then((data) => console.log(JSON.stringify(data)));
}

Answer №1

Here is the solution you have been searching for->

  let desiredItem;

  fetch('https://cors-anywhere.herokuapp.com/https://www.pathofexile.com/api/trade/search/Standard', {
    method:'POST',

    headers: {
      'Accept': 'application/json, text/plain, */*',
      'Content-type':'application/json'
    },
    body:JSON.stringify({"query": {"status": {"option": "online"}, "name":desiredItemName, "stats": [{"type": "and", "filters": []}]},"sort": {"price": "asc"}})
  })
  .then((res) => res.json())
  .then((data) => desiredItem = JSON.stringify(data));

JSON.parse(desiredItem).result

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

Is there a way to continuously switch a CSS animation class without needing a second click?

I am seeking a solution to animate the color and size of a div box, then return it to its original state when a button is clicked. Here is an example of my code: document.getElementById("andAction").addEventListener("click", function() { document.getE ...

Enter data into the appropriate columns

Within my Angular 6 application, I am creating a table with the following structure: Html: <table> <thead> <tr> <th> Property Details &nbsp; &nbsp; &nbsp; &nbsp; ...

How to Convert JSON into a DataFrame using Python?

I am working on converting JSON data into a Dataframe in order to visualize daily stock information and perform analysis. The goal is to transform the data into a graph for analysis purposes. "Meta Data": { "1. Information": "Daily Prices (ope ...

Optimizing the rendering of Font-awesome CDN JS for better performance on Pagespeed Insights

Instead of directly linking to the Font Awesome CSS, I have chosen to leverage the JavaScript provided by the trustworthy and efficient Font Awesome CDN. This allows for asynchronous loading of icons on my homepage, ensuring a seamless user experience. How ...

The methods $.get() and $.ajax() in jQuery are failing to retrieve data from PHP

I've been trying to use a script to display a message from a PHP file after a click event, but I've run into issues with both jQuery $.get() and $.ajax(). With $.ajax(), I get an alert with an empty message, while $.get() alerts "null". load.php ...

Icon for local system displayed on browser tab

I am currently trying to set a Browser Tab icon for the local system, but it is not working. However, when using an HTTP static icon, it works perfectly. Can someone please help me understand what the issue might be? PAGE 1 : Icon Not Showing <link re ...

Eliminate redundant data by utilizing oData to streamline information

I'm trying to clean up my data and eliminate duplicates using oDATA. Currently, I am using !summary=Name in my query, however it's not creating groups and providing the results as expected. Below is my query: http://localhost:12585/OData.svc/Med ...

Spinning a rectangular grid with JavaScript

I am currently developing my own version of Tetris. My main focus at the moment is creating a function that can rotate a 2D variable array by 90 degrees (or -90). For instance, if we have an array like: "-T-", "TTT" The expected outpu ...

Is my utilization of the Promise feature correct?

I am currently using node to fetch data from a URL with the help of cheerio. const request=require('request'); const cheerio=require('cheerio'); const Promise = require('promise'); The function getDataParms(parm1, parm2) ret ...

Paste a data point from an Excel spreadsheet into a JavaScript script

I'm encountering a major challenge. Currently, I am creating a login process for a client and here is the approach I have taken: function Jump(pal){ if (pal=='10528'){window.open('http://www.google.es','_parent')} Subs ...

Utilizing React and Google Code to Enhance Lead Conversion Pages

I have developed a basic react application featuring a contact form. Upon submission, I aim to display the Google Code for the lead Conversion Page within the application. <!-- Google Code for Purchase Conversion Page --> <script type="text ...

Looping through an array and appending distinct elements to a fresh array

I am currently facing an issue and seeking feedback on how to resolve it. Below is the JSON data: questions: [ { question: 'lala', answer: 'papa', categories: ['Handla'] }, { question: ...

Guide on the correct way to register plugins in Hapi.js

I attempted to create a simple server following the instructions on hapi's official website, but encountered an issue: I couldn't register plugins. var Hapi = require('hapi'); var server = new Hapi.Server(); server.connection({port: ...

"Unexpectedly, the original values of an array were altered by a Javascript

After creating a constructor function to generate an object, I set up an array named arr1 with initial values. Next, I use the map function on arr1 to create a new array called arr2. However, I noticed that the original arr1 was altered. Could this be du ...

Adding a KendoColorPicker to a column in a Kendo Grid

When using AngularJS with a Kendo UI grid, I need to have a column that includes a colorPicker. Below is the code I have implemented: $scope.thingsOptions = { sortable: "true", scrollable: "true", toolbar: [{ name: "create", text: "Add Profile ...

The error message [ERR_HTTP_HEADERS_SENT] is indicating that headers cannot be modified after they have already been sent to the client in a node.js and express

Attempting to retrieve data by Id from records stored in a MSSQL database. For example, trying to make a GET request in Postman like this: localhost:3200/api/v1/players. Encountering an error message: node:_http_outgoing:576 throw new ERR_HTTP_HEADERS_ ...

Sending a parameter value from a blade view in Laravel to a controller: tips and tricks

What is the best way to pass the value "{{$ item-> id}}" to a method in a controller? For example, if we have show.blade.php with the value: "{{$ item-> id}}" In MyController.php, how can we utilize this value within the method: public function ...

Easily transfer files without the need to refresh the page by utilizing the power of AJAX

In my page file-upload.jsp, I have the following code snippet: <form action="" id="frmupload" name="frmupload" method="post" enctype="multipart/form-data"> <input type="file" id="upload_file" name="upload_file" multiple="" /> <in ...

Creating camera shake in Three.js: A beginner's guide

I've been searching for hours online and I can't seem to figure this out. Is there any way to achieve this? If so, please share the steps with me. I found a code snippet but I'm unsure how to implement it properly. Can someone guide me on ho ...

What is the best way to use ajax to append a value to an input if it is empty, or add a comma with

I recently came across this answer and implemented the following code: Here is the Ajax receiver: success: function(data) { jQuery("#assigncat").val(function(i,val) { return val + (val ? '' : ', ') + data.cat_id; ...