Casting types of objects in Angular2 using TypeScript

Trying to extract the model object from the JSON obtained through a http response call.

The following JSON represents the body of the http response,

{

"dataType": "RWSupplier",
"partyName": "Lifecare Pharmaceuticals",
"partyShortName": null,
"partySecondaryName": null,
"partySecondaryShortName": null,
"sortingName": "Lifecare Pharma",
"mailingName": null,
"entityType": "SP",
"partyType": "OG",
"partySubType": null,
"extPartyId": null,
"comments": null,
"prGenderType": null,
"prBirthDate": null,
"prSalutation": null,
"statusCode": null,
"lastUpdateDate": "2017-03-06T04:30:00.000+0000",
"lastUpdateUser": "RwAdmin",
"tinNum": "33450701833",
"cstNum": "790052 dt. 4/4/2001",
"stNum": null,
"dlNum1": "5324/MIII/20B",
"dlNum2": "5205/MIII/21B",
"limitList": [ ],
"tagList": [ ],
"buId": "510",
"partyId": "SP001011001" }

An interface has been created for the above JSON data as shown below,

export interface SupplierBrief {
dataType: string;
partyId: string;
buId: string;
partyName: string;
statusCode: string;
comments: string; }

Not all properties from the rest call are needed.

To optimize caching and reduce memory usage, unnecessary properties need to be omitted. The service is designed as follows,

return this.http.request(path, requestOptions).map((response: Response) => {
            return response.json() as models.SupplierBrief;
        });

However, the SupplierBrief still includes all properties returned by the rest call.

There might be a misunderstanding with the concept of model objects. Any corrections or clarifications would be appreciated.

Answer №1

Sorry, the responsibility lies with you. Generate a fresh object, assign the necessary values, and then submit it.

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

Incorporating responsive design with React and Typescript

Trying to utilize React with TypeScript, I aim to dynamically generate components based on a field name // Storing all available components const components = { ComponentA, ComponentB, }; // Dynamically render the component based on fieldName const di ...

Having difficulty utilizing defineProps in TypeScript

For some time now, I've been utilizing withDefaults and defineProps. Unfortunately, this setup has recently started failing, leaving me puzzled as to why! Here's a simple SFC example: <script setup lang = "ts"> const props ...

Retrieve both the key and value from an array of objects

I have been scouring the internet for a solution to this question, but I haven't come across anything that fits my needs. Let's say we have an array of objects like this -- "points":[{"pt":"Point-1","value":"Java, j2ee developer"},{"pt":"Point ...

There are distinct variations between Aspx files and text files when it comes to parsing data

Upon attempting to parse my JSON code, I encountered an issue where the code successfully parsed data from http://www.gorkemkaradogan.com/Personnel.txt, but failed to run when provided with the URL for http://www.gorkemkaradogan.com/Personnel.aspx. The JSO ...

What mysteries lie within an unfamiliar JSON object or Array?

Looking to access a list of friends' names from the Facebook API in an Android app. Wanting to figure out how to read JSON objects and arrays during this process. I have received JSONObject and/or JSONArrays, but I am unsure about their contents. I c ...

Exploring the distinction between "() => void" and "() => {}" in programming

Exploring TS types, I defined the following: type type1 = () => {} type type2 = () => void Then, I created variables using these types: const customType1: type1 = () => { } const customType2: type2 = () => { } The issue surfaced as "Type ...

When using jQuery to parse JSON, I am unable to make changes to an array

inventory = new Array(); $.getJSON('items.php', function(data){ $.each(data , function(i,jsonData) { inventory[1] = "item"; }); }); alert(inventory[1]); This code is supposed to display the items in the inventory, but it's ...

Unable to construct a node typescript project using solely production dependencies

I am currently working on a Node TypeScript project that utilizes various third-party libraries such as express. To ensure type safety, I typically install the @types/express module as a dev dependency following common instructions. The installation works ...

Issue with pandas DataFrame json data conversion/extraction loop not functioning as expected

Currently, I am in the process of following an EDA walkthrough where I aim to convert/extract JSON data within a dataframe using a loop to handle columns containing JSON data. To achieve this, I have established a list for the loop to iterate through and s ...

error in jquery when splitting

I encountered an issue while trying to split data for checkboxes. var ukuran = data['model'].ukuran_model; var cek = ukuran.split(",").join('], [value='), $inputs = $('input[name^=ukuran]'); $inputs.filter('[value=&a ...

The TypeScript script does not qualify as a module

Just starting out with TypeScript and encountering a simple issue. I'm attempting to import a file in order to bring in an interface. Here's an example: Parent: import { User } from "@/Users"; export interface Gift { id: number; ...

Python KeyError: When Attempting to Retrieve JSON Data With an Index of 0

I have encountered an error while using selenium to verify a value in a json request. My approach involves first logging in, as the response is dependent on being logged in. I am attempting to retrieve a user's balance from the json and display it to ...

What could be causing me to receive an undefined result when attempting to retrieve a specific element?

Why am I receiving 'undefined' for my ID? I am currently working on a NextJS app and attempting to create a route to retrieve a specific element by its ID. Below is the code for my route: const { events } = require('../../../db.json') ...

Steps for utilizing a Get() method to view a response within Angular

I am having trouble with implementing an API call on a page and I'm unsure about what's wrong with the Subscribe/Observe method. Currently, this is the code that I have: import { Component, OnInit } from '@angular/core'; import { Ro ...

Using TypeScript to implement functional props in React applications

When passing functional props from a parent to a child component with typescript: import react, {Component} from 'react' import Child from './Child' //some type declaration class Parent extends Component<{IProps},{IState}> { stat ...

Extract data from a JSON field within a Snowflake table and insert the extracted information as multiple rows into a new Snowflake

I am facing a challenge with the 'reactions' field/column in a Snowflake table named 'tbl'. This table consists of multiple columns and records, with the 'reactions' field being a json array. The json data within this field in ...

Converting webpage JSON data to Python script encountered an error: urllib.error.HTTPError: HTTP Error 403 - Forbidden access

I successfully developed a program that functions with a local JSON data file! Code Block: def datas(self): with open ("C:\\Users\\Messi\\Desktop\\Python\\\\tek.json ...

The seamless merging of Angular2, TypeScript, npm, and gulp for enhanced development efficiency

I'm fairly new to front-end development and I am currently working on an application using Angularjs2 with TypeScript in Visual Studio 2015. I have been following the steps outlined in this Quickstart https://angular.io/docs/ts/latest/cookbook/visual- ...

Removing a targeted element from an array in Angular

After receiving a JSON array object in Angular using TypeScript, I am attempting to remove a specified object from it. However, my attempts at deletion have been unsuccessful. addCategorySub(categorySub: CategorySubModel, index: number) { categorySub.id ...

What is the process for verifying JSON format validation?

When my program receives a JSON file containing information for a service, I need to verify its validity (checking if all necessary keys exist) before running the service program. The standard JSON format required for this program is as follows: { "se ...