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

An effective approach to automatically close an Expansion Panel in an Angular Mat when another one is opened

I am attempting to implement functionality where one expansion panel closes when another is opened. By default, the multi attribute is set to "false" and it works perfectly when using multiple expansion panels within an accordion. However, in this case, I ...

Preventing Page Refresh when Button is Clicked in Angular

How can I prevent page reload when a button is clicked in Angular? I'm developing a quiz application in Angular where I fetch random questions and options from an API. When users select an option, the next question should appear without reloading the ...

Tips for converting a JSON string into a table format with jq

Just getting started with Bash scripting and recently discovered jq for JSON manipulation. I'm trying to convert a JSON string into a table format suitable for displaying in the terminal. [{ "name": "George", "id" ...

Issue with Angular 7 service worker caching audio files leads to range header problems in Safari browser

I am encountering an issue in my Angular application with the range request header for audio files when using Safari. When requesting audio from a server, the duration of the audio file is returned correctly. However, when requesting the audio from the ser ...

Refine intricate nested list JSON queries

I am currently working with the following data: { "additionalInfo": [], "id": "8d929134-0c71-48d9-baba-28fb5eab92f2", "instanceTenantId": "62f4c8ab6a041c1c090f ...

Discover the location of items within an array

Currently, I am working with a JSON object that has the following structure. My objective is to determine the index based on ID in order to retrieve the associated value. The indexOf function appears to be suitable for arrays containing single values, but ...

Using the useEffect hook with Redux-Toolkit dispatch causes an endless cycle of execution

Issue I am encountering an infinite loop problem when using useMutation from react-query to make post requests, retrieve user information from JSON, and then store it in my redux store using useEffect based on the status provided by the useMutation hook. ...

Learn how to define an object with string keys and MUI SX prop types as values when typing in programming

I want to create a comprehensive collection of all MUI(v5) sx properties outside of the component. Here is an example: const styles = { // The way to declare this variable? sectionOne: { // What type should be assigned here for SXProps<Theme>? } ...

Tips for customizing the appearance of date and time formats

Does anyone know how to retrieve this specific time format using Angular2 TypeScript? 2016-9-25T05:10:04.106Z I've tried searching online but couldn't find a straightforward solution. When attempting this in TypeScript, the following results a ...

Utilizing JSON to Fetch User Input in MVC 3

Currently, I am a beginner in ASP .NET MVC 3 and working on my final year project using it. I would appreciate assistance with the following: I want to send data that the user enters in multiple rows as JSON to the controller for processing, and then rece ...

Preventing the (click) function from being activated during dragging in Angular 10

My div contains an openlayers map setup as shown below: <div id="map" (click)="getInfo($event)" class="map"></div> Whenever I drag my mouse to move around the map, the getInfo function is triggered. Is there a way to make it trigger only when ...

Modifying data within nested objects using Typescript

Imagine having an object like this: { b954WYBCC4YbsMM36trawb00xZ32: { activity1: "pending", activity2: "pending" }, ​ pby0CAqQ1hTlagIqBTQf6l2Ti9L2: { activity1: "pending", activity2: "pending" } } with the in ...

Converting JSON into a List of strings

It seems like a simple task, but as a newcomer, I am struggling to quickly find the answer: I need to retrieve a list of file names (List<string>) in a .Net 2.0 desktop application using WebClient to make a request to a WebAPI REST service. Here is ...

Unable to instantiate a Vue reference with a potential null type

When working in Vue v3, I encountered a situation where I needed to create a ref with a type that could possibly be null. This specific scenario in my app involves data that starts off as null and then gets populated after loading completes. Just to illus ...

Unable to display complete content of Ionic 3 webpage

Trying to print a specific part of an Ionic page which contains a long list of items. However, encountering an issue where the entire list doesn't fit on one page and requires scrolling down to view all items. Expecting the print dialog, triggered by ...

Implementing multer diskStorage with Typescript

I'm currently in the process of converting a node.js server to TypeScript. Here is what my function looks like in Node: const storage = multer.diskStorage({ destination: function (req, file, cb) { const dir = './uploads/'; ...

What is the best way to showcase Json API content on an HTML page?

I possess a strong proficiency in html and css, however I lack experience in utilizing javascript. My aim is to showcase the date received from an API onto an html page Despite several attempts, I have not been able to achieve success yet. var getJSON ...

Advantages of Using JSON for POSTing Data to a Server with jQuery

While browsing the internet, I've come across various examples of using jQuery to send AJAX POST requests with JSON encoded data to a server. I'm curious about why it's necessary to encode the data in JSON first. Wouldn't it be more eff ...

Merging data from different columns in a table to form a JSON structure

I have a database set up in athena that contains the following information: type state city zipcode ------------------------------- hot az phx 85281 hot tx dal 12345 cool wa sea 67890 cool ny nyc 67856 My g ...

Utilize Angular 10 to send a post request and subsequently trigger another request upon successfully completing the first

I am looking for a way to register a user on the backend and then sign them in sequentially. The register route will create the user, while the sign-in route will return a UserModel object if successful. If registration fails, an error will be returned f ...