Update the class attributes to a JSON string encoding the new values

I have created a new class with the following properties:

'''

import { Deserializable } from '../deserializable';

export class Outdoor implements Deserializable {
    ActualTemp: number;
    TargetTemp: number;
    Day: number;


    deserialize(input: any): this {
        // Assign input to our object 
        if(input){
          Object.assign(this, input);
        }
        return this;
      }

    toJSON() {
      return Object.assign({}, this);
    }
}

'''

The toJSON function is used to convert the class data into a JSON String by calling:

'''

const resource = JSON.stringify(this.appEngineMsg.Outdoor.toJSON());

'''

{"ActualTemp":60, "TargetTemp":55,"Day":23}

If I modify the values of this.appEngineMsg.Outdoor.TargetTemp or this.appEngineMsg.Outdoor.ActualTemp, I want to receive the following JSON strings:

{"Outdoor":{"TargetTemp":100}}

{"Outdoor":{"ActualTemp":100}}

What would be the most efficient way to achieve this?

Answer №1

I'm sorry, your inquiry lacks clarity. Are you seeking to display two separate JSON objects for each property?

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

Struggling to track down the issue in my ts-node express project (Breakpoint being ignored due to generated code not being located)

For my current project, I decided to use the express-typescript-starter. However, when I attempted to debug using breakpoints in VS Code, I encountered an issue where it displayed a message saying "Breakpoint ignored because generated code not found (sourc ...

Every time Chrome on Android returns a keyCode of 229

Here is a snippet of code that I am having trouble with: ... @HostListener('keydown', ['$event']) onKeyDown(evt: KeyboardEvent) { console.log('KeyCode : ' + evt.keyCode); console.log('Which : ' + evt.which); ...

The content security policy is preventing a connection to the signalr hub

Currently, I am developing an application using electron that incorporates React and Typescript. One of the features I am integrating is a SignalR hub for chat functionality. However, when attempting to connect to my SignalR server, I encounter the followi ...

Verify the validity of an image URL

I am attempting to create a function in TypeScript that checks the validity of an image source URL. If the URL is valid, I want to display the image using React Native Image. If the URL is invalid, I would like to replace it with a local placeholder imag ...

PhantomJS version 2.1.1 encountered an error on a Windows 7 system, displaying "ReferenceError: Map variable not found."

I've been utilizing the "MVC ASP.NET Core with Angular" template. I'm attempting to incorporate phantomJS and execute the tests, but encountering the following errors: ERROR in [at-loader] ..\\node_modules\zone.js\dist&bs ...

Acquiring mapping information through JSON data retrieval

Overview : Each levelNum has three corresponding dropdowns. For example, the dropdown for levelNum2 includes (Department-Unit-1, Department-Unit-2 & Department-Unit-3), levelNum3 includes (Division-Unit-1 & Division-Unit-2), and levelNum4 includes ...

The horizontal overflow is malfunctioning, resulting in only a limited number of columns being visible on the screen

I am facing an issue with the CSS for my table. Despite using overflow-x: scroll, only half of the columns are being displayed on the screen out of the 15 total columns. Can anyone provide assistance with this problem? .table { font-family: Roboto,"He ...

Creating an Asynctask for handling JSON parsing and updating the user interface

Seeking assistance in optimizing this AsyncTask code for JSON Parsing in Android. The objective is to update multiple list views with different data based on the input "TAG_TYPE". Below is the common class being called: public class Onlinetip extends Asy ...

Retrieve unique values based on two or more criteria from an array in TypeScript

Presented here is an array. https://i.stack.imgur.com/zHXim.png The desired pattern is: https://i.stack.imgur.com/EGUiM.png I am interested in retrieving unique "CityRef" and "City". Subsequently, locating all items associated with them. ...

The Plotly display features a white space with a legend, but the map is missing from

I am having trouble creating a choropleth map of Italy at the regional level using Plotly. Despite following their tutorial, I keep getting a white area with just a legend and no actual map or data displayed. My goal is to color code the Italian regions b ...

Enhance your viewing experience by zooming in and out with ng2-pdf-viewer

Currently, I am utilizing ng2-pdf-viewer to display PDF files within my application. <pdf-viewer [src]="pdfSrc" [page]="page" [zoom]="1.1" style="width: 100%;" I am looking to incorporate zoom in and zoom out buttons. Doe ...

Generating instances using TypeScript generics

Looking to create a factory for instantiating classes with generics. After checking out the TypeScript docs, everything seems to work as expected. Here's a simplified version of how it can be done: class Person { firstName = 'John'; ...

What is the best way to terminate a Node.js app using a scheduler?

I've been attempting to halt my cron task and shut down the entire nodeapp after 5 executions, but despite trying various methods, all attempts have failed. The message "time to quit" continues to appear in the log every minute. What would be the mos ...

The use of `super` in Typescript is not returning the expected value

Trying to retrieve the name from the extended class is causing an error: Property 'name' does not exist on type 'Employee'. class Person { #name:string; getName(){ return this.#name; } constructor(name:string){ ...

Exploring Ways to Navigate to a Component Two Steps Back in Angular

Let's say I have three routes A->B->C. I travel from A to B and then from B to C. Now, is it possible for me to go directly from C to A? ...

Is there a way to generate random numbers that will create a chart with a general upward trend?

Are you looking for a solution to generate random numbers for charts that trend upwards and to the right? I am currently utilizing a JavaScript charting engine, so I will require numbers in JSON format eventually. However, I am open to alternative methods ...

Exploring the functionality of surveyjs in conjunction with react and typescript

Does anyone have any code samples showcasing how to integrate Surveyjs with React and TypeScript? I attempted to import it into my project and utilized the code provided in this resource. https://stackblitz.com/edit/surveyjs-react-stackoverflow45544026 H ...

Sending JSON Data with Javascript Post Request

I've been attempting to send a JSON payload via a JavaScript script, but my webhooks don't seem to recognize the payload no matter what I try. Here is the code that I compiled from various online resources: let xhr = new XMLHttpRequest(); ...

How to Apply a CSS Class to the Body Tag in Angular 2.x

How can I add [class.fixed]="isFixed" to the body tag when Angular 2.x is bootstrapped inside the body (outside my-app)? <html> <head> </head> <body [class.fixed]="isFixed"> <my-app>Loading...</my-app> </body> & ...

What is the reason for webpack adding "-es5" and "es2015" to my TypeScript files?

When Webpack converts my typescript files into Javascript files, it appends -es5 to the name. For instance, I expect the file to be named background.js, but it actually generates 4 separate files: background-es5.js background-es5.js.map background-es2015. ...