Receiving JSON data in TypeScript and displaying it in a structured table format

I am just starting to learn TypeScript,

I need to be able to handle JSON data of varying sizes...

Once I receive the data, I want to display it in a table format...

The structure of my JSON data will resemble this:

[{"regionID":1 "regionname":"Can"},

{"regionID":1 "regionname":"Cen"}]

Additionally, the fields in the table should not be editable...

Answer №1

To tackle this task in a TypeScript-friendly manner, one could start by defining a class named "region":

class Region {
  regionId: number;
  regionName: string;

  constructor(id, name) {
    regionId = id;
    regionName = name;
  }
}

The next step would involve converting the resulting JSON into an array of instances of that class.

const regions: Region[] = [];

JSON.parse(myJson).forEach(item => {
    regions.push(new Region(item));
});

Displaying this data in a table should not be too different from how it is done in JavaScript; TypeScript compatibility should not pose any problems in this scenario (If you require further assistance on table display, consider asking a separate question as it may be off-topic here).

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

Modifying Array Values in Angular 7

I am currently dealing with a complex array where questions and their corresponding answers are retrieved from a service. Upon receiving the array, I aim to set the 'IsChecked' attribute of the answers to false. The snippet of code I have written ...

What's the best way to convert static data from JSON files within the Django framework?

I am dealing with a json file that contains an extensive list of geographic locations [ { "id": 1, "name": "Afghanistan", "iso3": "AFG", "iso2": "AF", ...

Deciphering JSON with the help of a variable in PHP

My goal is to display the price of each item using the market hash name. I can successfully return the JSON when the master is set to a single item (e.g. MP7 | Olive Plaid (Field-Tested)), but when I use a variable (checkgrd->market_hash_name, which was ...

Using React Material UI in VSCode with TypeScript significantly hampers autocompletion speed

When including the "@mui/material", Visual Studio Code may become unresponsive, leading to Typescript warnings appearing after 10-15 seconds instead of the usual less than 10 milliseconds. For example: import { Button } from '@mui/material&a ...

Exploring Json Parsing in C# Using HTTP Requests

I'm experiencing issues with reading JSON from our local API. To troubleshoot, I am using a well-known public JSON site for testing: https://jsonplaceholder.typicode.com/todos This is the JSON response from my local API: https://i.stack.imgur.com/Ky ...

The function file_get_contents is not retrieving any content

Currently, I am employing the file_get_contents function to retrieve data in JSON format. $queryurl = "http://cloud.softpanda.com.au:9874/loyalty/customer/query-account?user=foo&pass=bar&format=json"; $queryurl = $queryurl . "&number=" . urlen ...

Error in NextJS: Attempting to access a length property of null

Does anyone have insights into the root cause of this error? warn - Fast Refresh had to perform a full reload. Read more: https://nextjs.org/docs/basic-features/fast-refresh#how-it-works TypeError: Cannot read properties of null (reading 'lengt ...

Unveiling Insights from a JSON File: Data Extraction

I have a JSON file named pio2.json that contains the following data: { "controles":[{ "chart":[{ "type":"columns", "title":"Pollitos" }], "datos":[{"key":"Math","value":98}, {"key":"Physics" ...

Using Golang to encode JSON for parsing in JavaScript

I am working with a struct that looks like this: type User struct { Login string `json:",string"` PasswordNonce Nonce `json:",string"` PasswordHash HashValue `json:",string"` CreatedOn time.Time `json:",string"` Email ...

Converting URL-esque information to JSON using JavaScript

Does anyone have a solution for converting an array of URL-like data into JSON format? For example, how can we convert the array ["a.b.c.d", "a.c.e.f", "a.b.c.g"] into the following JSON structure: items:{ text: "a", items:[ { ...

Sending a unicode PHP variable to JavaScript is a breeze

I am attempting to transfer the titles and excerpts of Persian Wordpress posts to JavaScript. Below is the code in a .php script file: function change(){ document.getElementById("link").innerHTML = '<a href="$links[2]">$titles[2]< ...

"Unraveling the mystery: Deserializing unidentified properties using JSON-B

Is there a way to deserialize the JSON data with dynamically generated numeric keys into a Map using Quarkus' JSON-B implementation? The challenge lies in dealing with unknown properties and mapping them to a Map<Long, MyObject> without manually ...

Tips for incorporating the "build" directory into the Travis-CI build process and deployment of an npm module

Currently, I am working with a Typescript module that has a directory ./src And I also have travis-ci set up for the project. language: node_js node_js: - 5.1.0 install: - npm install - npm install -g mocha - npm install -g gulp - npm install -g tsd - ...

Different methods for extracting specific information from JSON data through deserialization

I need assistance with deserializing json data. The structure of my json data is as follows: { "batchcomplete": "", "query": { "pages": { "62413": { "pageid": 62413, "ns": 0, "title": "espri" } } ...

Tips for declaring a non-reactive instance property in Vue.js with TypeScript

I am currently in the process of transitioning my Vue.js components to TypeScript. In accordance with the recommendations provided in the documentation, I attempted to utilize Vue.extend() for my component implementation. The code snippet for my component ...

Issues with saving nodes containing sizable properties in Neo4j

When working with Neo4j in Java using CYPHER and JSON through http://hostname:7474/db/data/transaction/commit, I encounter an issue. In my testing, I am trying to create nodes using the following CYPHER statements: MERGE (a:LABEL1 { name: 'nameNNN&a ...

Using NPM in combination with React and TypeScript to incorporate AMD modules

I am currently in the process of setting up a development environment for an application that is written in TypeScript using React. I already have existing TypeScript code that compiles to ES5 and AMD modules. My goal is to avoid any JavaScript transpilat ...

Using the concat operator along with the if statement in Angular to make sequential requests based on certain conditions

Managing multiple HTTP requests in a specific order is crucial for my event. To achieve this, I am utilizing the concat operator from rxjs. For instance, upon receiving data from the first request, I update local variables accordingly and proceed to the ne ...

When you call setTimeout from a static function, it does not get executed

Having a problem with starting a timer in my utility typescript class. The static function initTimer() uses setTimeout but when called from a react component, the timer doesn't start. StyleWrapper.tsx const StyleWrapper: FC = (props) => { cons ...

Freezing in IE/Safari due to AJAX jQuery interactions

Feeling frustrated and seeking help. I am currently executing this particular script: <script type="text/javascript" charset="utf-8> jQuery(window).ready(function(){ //alert('running'); var sold = false; var l ...