Using TypeScript to work with JSON fields that include the '@' symbol

While working on an Angular project with TypeScript, I am facing a challenge of displaying certain JSON fields obtained from a POST request to the user.

One of the fields begins with the '@' symbol, which is a reserved word in Angular causing

this.timestamp=response.@timestamp

This results in a compile error -

Identifier expected

How can I work around this issue and escape the problematic character?

Answer №1

One possible solution is to utilize the bracket property accessor method, which can be found at this link.

By implementing this code snippet: "this.timestamp=response['@timestamp']", you may achieve your desired outcome.

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

How can I identify duplicate values within two distinct javascript objects?

Consider two sets of JavaScript arrays containing objects: var allUsers=[{name:"John",age:25},{name:"Emily", age:30},{name:"Michael",age:22}] and var activeUsers=[{name:"John",status:"active"},{name:"Sarah", status:"active"}] I am attempting to iterat ...

Errors encountered while starting Angular due to issues in package.json configuration

Summary: Encountered an error while using 'Angular' for the first time, indicating tsc was not found in the package.json file. Details: As a beginner with Angular, I followed an example from a book and attempted to start it with np ...

Creating an Angular component to display a dynamic table using ngFor directive for a nested JSON data structure

Currently diving into Angular (version 8) and grappling with the following JSON structure {layer1 : [ { id: 'lay1', name: 'first layer', results: [ { rows: ...

Utilizing Jackson Annotations for Generating Local JSON Pointers

My class structure is as follows: public class A { @Id public String id; public List<B> bs; } public class B{ public String name; public List<B> preconditions; } When I return an instance of this class, I get a nested ...

Cancel promise chain after action dispatch (rxjs)

My goal is to achieve the following: this.jobManager .queue( // initiate a job ) .then( // perform additional actions, but stop if `ABORT` action is dispatched before completion ) .finally( // carry out necessary ...

Searching for an object in a more efficient manner

At times, I often find myself needing to locate a specific object within an array of objects where the key I am searching for matches a particular value. For instance: var cars = [ { id:23, make:'honda', color: 'green' }, { id ...

Navigating through nested JSON objects in React to display data effectively

I have been struggling for hours to find a solution to this problem with no success. I really need your assistance. The task at hand involves looping through a JSON file and creating a user interface that consists of multiple columns, each containing vari ...

Is there a way to set up an HTTP service in Orbeon by utilizing HTTP parameters and extracting data from a JSON response?

Currently, I am exploring the potential of Orbeon for creating forms within my application. This particular application makes use of HTTP web services by passing and receiving JSON data through HTTP parameters. I would like to know how I can set up Orbeon ...

How to efficiently mock the $window object in Angular unit tests

Attempting to unit test an angular custom service written in Typescript has been a challenge for me. The service is designed to read a global variable defined on the Window object and I have made it promise-based for potential future AJAX calls. Below is a ...

Angular: facing difficulty displaying static html pages on server, although they render correctly when run locally

Within my Angular project, I have stored a few static html files (specifically sampleText.html) in the src/assets/html folder. In one of my components, I am attempting to fetch and display this file. The following code is being used for this purpose. Every ...

Reactive form enabled for Angular control

In order to meet the required format for a social security number input field using reactive forms, it must adhere to the following conditions: The format should be ###-##-####. Limited to 9 digits without including the dashes (11 characters with dashes) ...

Velocity: The initial parameter was not recognized as a property mapping

I've been experimenting with Velocity for animations (without jQuery), but I'm running into an issue where I keep getting this error message: Velocity: First argument ([object HTMLDivElement]) was not a property map, a known action, or a regis ...

I require the output to be saved in a txt file rather than a JSON object

Can this code be modified to output its results to a text file rather than a JSON/curl object? We are troubleshooting a specific sku and need to view the long query's output that comes before this snippet: foreach($group_sets AS $group_set) { $b ...

Angular2: Unable to locate the 'environment' namespace

After configuring my tsconfig.json, I can now use short import paths in my code for brevity. This allows me to do things like import { FooService } from 'core' instead of the longer import { FooService } from '../../../core/services/foo/foo. ...

Guidance on showcasing the current day's weekday name through TypeScript

I am perplexed about how to begin in TypeScript after successfully setting up the display using gate. ...

Is it feasible to deliver push notifications from one application on a single device to the identical application on a different device using Ionic 4?

Is it possible to send push notifications from one app on a device to the same app on another device using Firebase Cloud Messaging in Ionic 4? I'm hoping to be able to create a text and a simple button in one app, and automatically send FCM push not ...

Ruby Stateful JSON Parsing Tool

I am currently working with a Ruby server that is continuously reading from a flat file which gets updated every second by another server. This flat file is in JSON format, and I want the server to only read the new data instead of parsing the entire fil ...

Experiencing difficulties while attempting to install the Angular-cli tool and encountering errors

Following recommendations, I executed "npm install -g angular-cli" to install the CLI tool. I have successfully installed Windows tools using "npm install --global --production windows-build-tools" and also "npm install -g node-gyp" via PowerShell running ...

What is the process for integrating an extension function into an Express response using TypeScript?

I am looking to enhance the Response object in Express by adding custom functions. Specifically, I want to introduce a function: sendError(statusCode: number, errorMessage: string) which can be called from anywhere like this: response.sendError(500, &qu ...

Navigating to the Login page in Angular 13

<app-navbar></app-navbar> <div class = "app-body"> <div class="app-sidebar"> <app-sidebar></app-sidebar> </div> <div class="app-feed"> <router-outlet name="main& ...