Showing posts with label JSON. Show all posts
Showing posts with label JSON. Show all posts

Thursday, July 13, 2023

How to read JSON list from JavaScript

To read a list of JSON objects in JavaScript, you can use the JSON.parse() function to parse the JSON string into a JavaScript object or an array.

Here's an example:

var jsonString = '[{"name":"Maximus","age":30},{"name":"Peter Parker","age":25},{"name":"Bob Krammer","age":40}]';

// Parse the JSON string into an array of objects
var jsonArray = JSON.parse(jsonString);

// Iterate over the array and access the properties of each object
for (var i = 0; i < jsonArray.length; i++) {
  var obj = jsonArray[i];
  console.log("Name: " + obj.name + ", Age: " + obj.age);
}
  

In the above example, the jsonString variable holds a JSON string representing an array of objects. The JSON.parse() function is used to parse the JSON string into the jsonArray variable, which becomes an array of objects.

You can then iterate over this array and access the properties of each object as shown in the for loop.

Note that the JSON string should be well-formed, with double quotes around property names and string values.

Hope this helps!

Tuesday, February 20, 2018

Paste JSON as Code - quicktype

quicktype infers types from sample JSON data, then outputs strongly typed models and serializers for working with that data in your desired programming language. To use this extension, just copy some JSON and use Edit/Paste JSON as Code.

This extensions works only in VS2017 as of now.

For a more powerful experience, including custom options and the ability to generate code from JSON Schema or multiple JSON samples, try app.quicktype.io.

Download here