Can a number value in a JSON object be converted to a string?

In my application, I have defined an interface:

export interface Channel {
  canal: string;
  name: number;
  status: string;
  temperature: number;
  setpoint: number;
  permission: boolean;
  percentOut: number;
}

[UPDATE] in the HTML file:

<input type="range" #inputRange min="5" max="30" value="channel.setPoint"  step="0.5" class="slider"  (change)= "putSetpoint(channel, inputRange.value)">

In the home.ts file:

putSetpoint(cb: Channel, value: number){
  console.log(value);
  cb.setpoint = value;
  this.homedata.setpointChannel(cb);
  console.log('setpoint call');
}

Next, I create a JSON object to send to the server:

setpointChannel(cb: Channel) {
  var chanObj = {
    channels : {
      canal: cb.canal,
      setPoint: cb.setpoint,
      name: cb.name,       
    }
  };
  console.log(chanObj);
}

However, the rendered JSON for setpoint is returned as a string:

channels: {canal: 0, setPoint: "21", name: "chambre"}

Answer №1

It appears that the issue lies with the cb parameter used in the setpointChannel method.

This parameter contains the state of setpoint as a string.

In order to assist you further, could you please provide the section of code where you are calling the setpointChannel method?

Answer №2

discovered it. Located in home.ts file:

putSetpoint(cb: Channel, value: number){
  console.log(value);
  cb.setpoint = Number(value);
  this.homedata.setpointChannel(cb);
  console.log('executing setpoint function');
}

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

Creating a Json autocomplete feature for category

Looking to implement categorized jquery autocomplete with Rails. Successfully retrieved JSON response: ["Air Canada to appeal Quebec court ruling on Aveos","First Nations meeting with PM in jeopardy","Neanderthals, humans may have missed each other","New ...

How to incorporate a JSON schema as an array in PHP

In my PHP code, I am attempting to insert a new key and its corresponding content into a JSON file. $content = file_get_contents($_POST["content"]); $decode = json_decode($content,true); $version = $_POST["version"]; array_unshift($decode['versions&a ...

Sending an array of elements to an API using Python

I'm currently working on a Python script that sends POST requests to an endpoint in order to create keywords and SMS responses. The goal is to post multiple zip codes and receive a specific response for each one, which should say "sorry, we're cl ...

Check out the JSON feed in Swift 3.0

I'm attempting to display my PHP result in an iOS app using the following code: func get() { //let url = NSURL(string: "http://www.w3schools.com/js/customers_mysql.php") let url = NSURL(string: "http://www.helpmewastetime.com/ser ...

Angular: Tailoring the Context Menu

Currently, I am utilizing a helpful tutorial to implement a custom context menu feature. The main issue I am facing is that when a user interacts with the list items, I want the correct index of each item to be displayed. However, at the moment, clicking o ...

Retrieve Username API for forgetful users

Currently, I am working on implementing a new REST service for our API, and I would like to gather some insights on the most effective approach. This service is designed to retrieve a user's email address in case they have forgotten their username. To ...

TypeScript function encountering issues with proper evaluation of set iteration

Whenever I attempt to run the code below, I consistently receive this console message: "undefined is not an object (evaluating 'this.courseAvailThisTerm')". Even though the courseAvailThisTerm() function functions properly in other scenarios. Any ...

Embedding image URLs fetched from JSON data within <li> elements

I have successfully retrieved a JSON response, which is displayed using the code below: Within my HTML document, I have the following structure: <ol id="selectable"></ol> In my JavaScript code, I make use of the following: <script type=" ...

Retrieve information dynamically from a JSON file using the get JSON function and iterate through the data

I possess a JSON file that I wish to utilize in creating dynamic HTML elements with the JSON content. Below is the provided JSON data: { "india": [ { "position": "left", "imgurl":"3.jpg" }, { ...

What is the proper way to specify the type for the iterable response of Promise.all()?

It's common knowledge that Promise.all will return settled promises in the same order of the requested iterable. I'm currently grappling with how to correctly define types for individual settled resolves. I am utilizing Axios for handling asynch ...

Issue: Module '/Users/MYNAME/Desktop/Projects/MYPROJECTNAME' not found

I am currently in the process of compiling Node using TypeScript, and I'm still getting acquainted with it. An issue I encountered was that my /src files were not being updated when I made changes and restarted the server. To troubleshoot, I decided ...

No data is generated when choosing from the dropdown menu in mat-select

I have a select function where all options are selected, but the selected sections are not shown. When I remove the all select function, everything works fine. Can you help me find the error? Check out my work on Stackblitz Here is my code: Select <m ...

Experimenting with NGXS selectors: A comprehensive guide

Hey there, I am currently utilizing the NGXS state management library in my application. I have a selector set up like this and everything seems to be functioning correctly. However, while testing the app, I encountered the following error message: "PrintI ...

Scroll to the top on every Angular 5 route change

Currently, I am utilizing Angular 5 for my project. Within the dashboard interface, there are various sections with varying amounts of content. Some sections contain only a small amount of information, while others have large amounts of content. However, w ...

Customizing the colors of the Input field in the Material UI Text Field component with CSS styling can elevate the overall

import { TextField } from "@mui/material"; import { FunctionComponent } from "react"; interface IProps { type: string; label: string; color: | "error" | "primary" | "secondary" | &quo ...

JavaScript alert causing disruption to Ajax requests

Currently, I am utilizing JQuery Ajax to retrieve a script from the server. $.ajax({ url: src, type: "GET", dataType: "script", timeout: transaction_timeout }).done(function(){}) .fail(function() { alert("Error in server");}) .always(funct ...

Are generic constraints leading to type inference selecting the incorrect candidate?

TypeScript Version: 2.6.0-dev.20170826 and 2.4.2 I'm questioning whether I've encountered a TypeScript inference bug or limitation, or if my code is simply incorrect. If the code is valid and it's an issue with type inference, I will repor ...

Tips for utilizing the patchValue method within a dynamic FormArray in Angular

When working with the first case (check out the DEMO link), patchValue() function can easily manipulate the select drop-down menu in a reactive FormGroup(), where only FormControl() is used. However, in the second case, I need to achieve the same functiona ...

How to add JSON data into a specific column of a table using

While exploring options for inserting arrays into single database columns, I came across an article that discussed inserting JSON strings. Unfortunately, the article did not provide detailed instructions on how to do this. Despite conducting further resear ...

What is the best way to send a search parameter to a URL?

In my asp.net core web api, I developed a method that generates an object with the string provided in the URL. I now have a search form that needs to pass this string to the URL and retrieve the objects containing it. Here is how I utilize the api: impo ...