๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ API โ€บ Response โ€บ json
Response: json() method - Web APIs | MDN
const myList = document.querySelector("ul"); const myRequest = new Request("products.json"); fetch(myRequest) .then((response) => response.json()) .then((data) => { for (const product of data.products) { const listItem = document.createElement("li"); listItem.appendChild(document.createElement("strong")).textContent = product.Name; listItem.append(` can be found in ${product.Location}. Cost: `); listItem.appendChild(document.createElement("strong")).textContent = `ยฃ${product.Price}`; myList.appendChild(listItem); } }) .catch(console.error);
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_json_parse.asp
JSON.parse()
... <p id="demo"></p> <script> ... Try it Yourself ยป ยท When using the JSON.parse() on a JSON derived from an array, the method will return a JavaScript array, instead of a JavaScript object....
Discussions

Parsing Json data from Api GET
Hi All - Im looking into getting the JSON formatted data on the for loop and console.log it The data from the json response is inside an array, and there is an object that contains the properties that I need to access. โ€ฆ More on forum.freecodecamp.org
๐ŸŒ forum.freecodecamp.org
1
0
February 13, 2021
jquery - How to get and display JSON API data with JavaScript - Stack Overflow
I am a beginner learning web development. I am trying to create a web app based on HTML, CSS, and JavaScript, which: Receives input from a user through an input field Retrieves JSON data through an More on stackoverflow.com
๐ŸŒ stackoverflow.com
javascript - How to fetch an array object from API json file - Stack Overflow
I have a JSON data and I would like to render only name from there. More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to get Json Data from an external WEB API to an JQUery autosearch text box end point
Hi @, I see this thread, it seems ... json data. If my answer work for you, could you pls accept my answer which could help others easily find the correct solution? ... Looking at your jQuery autocomplete issue, I can see the problem clearly. You're getting double-encoded JSON because you're treating JSON as a string when it should be handled as an object. ... Your API returns proper ... More on learn.microsoft.com
๐ŸŒ learn.microsoft.com
4
0
January 10, 2025
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ javascript โ€บ wc3qbk0b โ€บ javascript-fetch-json-example
How do I fetch JSON using JavaScript Fetch API?
The response.json() method reads the data returned by the server and returns a Promise that resolves with a JSON object. If you are expecting a text, call the response.text() method. For some servers, you must also send the "Accept: application/json" header to get the response in JSON format. In this JavaScript Fetch JSON example, we retrieve a JSON from the ReqBin echo URL using the fetch() method. Click Execute to run the JavaScript Fetch JSON Example online and see the result.
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ javascript
Parsing Json data from Api GET - JavaScript - The freeCodeCamp Forum
February 13, 2021 - Hi All - Im looking into getting the JSON formatted data on the for loop and console.log it The data from the json response is inside an array, and there is an object that contains the properties that I need to access.
๐ŸŒ
Since1979
since1979.dev โ€บ home โ€บ javascript array methods for json api data: filter, find & transform
JavaScript Array Methods for JSON API Data: Filter, Find & Transform
February 8, 2026 - Learn how to use ES6 JavaScript array methods like filter() and find() to process JSON API data. A practical guide for WordPress and React developers by Stephan Nijman.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 46103042 โ€บ how-to-get-and-display-json-api-data-with-javascript
jquery - How to get and display JSON API data with JavaScript - Stack Overflow
So I started this project with a decent understanding of HTML/CSS, but very little of JavaScript. I might go back to the tutorials again now before I continue. The aim would then be to understand the code in the different replies here, and try to write something on my own. 2017-09-07T20:11:29.733Z+00:00 ... $(document).ready(function() { function request(s){ $.ajax({ 'url': '//apis.is/car', 'type': 'GET', 'dataType': 'json', 'data': { 'number': s }, 'success': function(response) { // console.log(response); if (response && response.results && response.results.length) { response.results.forEach((car) => { Object.keys(car).forEach((key) => { $('<div>').html(`${key} : ${car[key]}`).appendTo($('body')); }); }); } } }) } $('#search').click(() => { request($('#val').val()); }); });
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Learn_web_development โ€บ Core โ€บ Scripting โ€บ JSON
Working with JSON - Learn web development | MDN
If you load this JSON in your JavaScript program as a string, you can parse it into a normal object and then access the data inside it using the same dot/bracket notation we looked at in the JavaScript object basics article. For example: ... First, we have the variable name โ€” superHeroes. Inside that, we want to access the members property, so we use .members. members contains an array populated by objects.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_json.asp
JavaScript JSON
When storing data, the data has to be a certain format, and regardless of where you choose to store it, text is always one of the legal formats. JSON makes it possible to store JavaScript objects as text. Text that defines an employees object with an array of 3 employee objects:
๐ŸŒ
ReqBin
reqbin.com โ€บ json โ€บ javascript โ€บ uzykkick โ€บ json-array-example
JavaScript/AJAX | What is JSON Array?
Unlike dictionaries, where you can get the value by its key, in a JSON array, the array elements can only be accessed by their index. The following is an example of a JSON array with numbers. Below, you can find a list of JSON arrays with different data types. The JavaScript/AJAX code was automatically generated for the JSON Array example.
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ javascript โ€บ n2ek7onb โ€บ javascript-array-to-json-example
How do I convert JavaScript array to JSON?
July 27, 2023 - The JSON.stringify(value, replacer, space) method in JavaScript converts arrays and objects to a JSON string. This is necessary when sending data over the network using XMLHttpRequest and the Fetch API (or other communication libraries).
๐ŸŒ
Quora
quora.com โ€บ How-do-I-get-JSON-data-from-an-API-using-JavaScript
How to get JSON data from an API using JavaScript - Quora
Answer (1 of 3): I would begin by familiarizing yourself with a fairly easy API that is good to practice with called JSONPlaceholder. Then I would also study asynchronous programming with a focus on Promises. Promise objects come with an aptly named `.then()` method. It allows us to say, โ€œI hav...
๐ŸŒ
jQuery
api.jquery.com โ€บ jQuery.getJSON
jQuery.getJSON() | jQuery API Documentation
This example, of course, relies on the structure of the JSON file: Using this structure, the example loops through the requested data, builds an unordered list, and appends it to the body. The success callback is passed the returned data, which is typically a JavaScript object or array as defined ...
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_json_arrays.asp
JSON Arrays
In JSON, array values must be of type string, number, object, array, boolean or null. In JavaScript, array values can be all of the above, plus any other valid JavaScript expression, including functions, dates, and undefined.
๐ŸŒ
PTC Community
community.ptc.com โ€บ t5 โ€บ ThingWorx-Developers โ€บ Search-through-array-of-JSON-objects โ€บ td-p โ€บ 859962
Solved: Search through array of JSON objects - PTC Community
March 7, 2023 - array.forEach(object => { // do your filtering here and array push here }); ... Services like find and filter work in ThingWorx, including ContentLoaderFunctions calls. This example works for me: let json = Resources["ContentLoaderFunctions"].GetJSON({ url: 'https://datausa.io/api/data?drilldowns=Nation&measures=Population' }); let result = { // JSON 'filtered': json.data.filter(row => (row['ID Year'] < 2015)) };
Top answer
1 of 4
1

Hi @Jose Daniel Navarro Brito ,

Looking at your jQuery autocomplete issue, I can see the problem clearly. You're getting double-encoded JSON because you're treating JSON as a string when it should be handled as an object.

Here's what's happening and how to fix it:

Your API returns proper JSON, but you're converting it to a string with ReadAsStringAsync(), then trying to return that string as JSON again. This creates the double-encoding you're seeing.

You need to deserialize the JSON string back into an object, then return that object as JSON:

[HttpGet]
public async Task AutoComplete(string search)
{
    var httpClient = _httpClientFactory.CreateClient("HousingWebAPI");
    using (var response = await httpClient.GetAsync("AsyncAutocompleteErf/" + search))
    {
        if (response.IsSuccessStatusCode)
        {
            var jsonString = await response.Content.ReadAsStringAsync();
            var data = JsonConvert.DeserializeObject>(jsonString);
            return Json(data);
        }
    }
    return Json(new List()); // Return empty array instead of null
}

Why this works:

  • Your external API returns valid JSON
  • You deserialize it into C# objects
  • You return those objects as JSON using Json()
  • jQuery receives proper JSON objects, not encoded strings

Regarding GET vs POST:

GET is perfectly fine for autocomplete. You're just retrieving data based on a search term, which is exactly what GET is designed for. POST would be overkill here.

Hope this helps!

2 of 4
0

it you look at the response in the browser debug tools the json string is probably encoded, because the AutoComplete action returned a string that is converted to a json. for example:

the string value [{"value":1}] when converted to json is: "[{\"value\":1}]"

the method Json is expecting an object to convert, not a string that contain Json Data. you ned to return content of type "application/json".

       var content = await response.Content.ReadAsStringAsync();
       return Context(content,"application/json");
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ javascript
Access the JSON Data from an API - JavaScript - The freeCodeCamp Forum
June 1, 2018 - Tell us whatโ€™s happening: Your code so far document.addEventListener('DOMContentLoaded',function(){ document.getElementById('getMessage').onclick=function(){ req=new XMLHttpRequest(); req.open("GET",'/json/cats.json',true); req.send(); req.onload=function(){ json=JSON.parse(req.responseText); document.getElementsByClassName('message')[0].innerHTML=JSON.stringify(json); // Add your code below this line console.log(json[2].a...
๐ŸŒ
ReqBin
reqbin.com โ€บ json โ€บ uzykkick โ€บ json-array-example
What is JSON Array?
June 11, 2022 - Unlike dictionaries, where you can get the value by its key, in a JSON array, the array elements can only be accessed by their index. The following is an example of a JSON array with numbers. Below, you can find a list of JSON arrays with different data types. ... JavaScript Object Notation (JSON) is a lightweight, language-independent, text-based data exchange format.
๐ŸŒ
JSON:API
jsonapi.org
JSON:API โ€” A specification for building APIs in JSON
By following shared conventions, you can increase productivity, take advantage of generalized tooling and best practices. Clients built around JSON:API are able to take advantage of its features around efficiently caching responses, sometimes eliminating network requests entirely.
๐ŸŒ
Reddit
reddit.com โ€บ r/frontend โ€บ curious statement about json arrays from my frontend dev
r/Frontend on Reddit: Curious statement about JSON arrays from my Frontend dev
September 1, 2022 -

So, he's telling me that frontend frameworks like React aren't performant if you use JSON arrays. He wants the JSON arranged to use only objects such as:

{ "key1": { "subkey1": "value1" }, "key2": { "subkey1": "value1" }, ... }

Rather than: [ { "id": "key1", subkey1": "value1" }, { "id": "key1", subkey1": "value1" }, ... ]

It's not really a big deal, but I just don't understand how using JSON arrays isn't performant. It seems weird, what am I missing?

Edit: Thanks for the Gold dude! It looks like my teammate gave me a Reddit gold. To all of you devs that participated in the discussion, thank you very much! We found some very clear answers that we can take with us going forward.