How can you manipulate and refine JSON data with Typescript Angular?

Here is a string I'm working with:

configValues="{listValues:[{name:chennai,attrs:[{id:1,name:kumar},{id:2,name:john}]},{name:bengalur,attrs:[{id:1,name:raj},{id:2,name:nick}]}]}"

This string contains a list of values based on city. I am trying to convert it into a JSON object and filter based on the name field.

I attempted the following method, but it resulted in an error stating "filter of undefined"

 var inputString=JSON.parse(JSON.stringify('configValues'));
 var outputString= inputString.listValues.filter(val=> val.name ==='chennai')

Can anyone assist me in converting this string to JSON and filtering using typescript?

Answer №1

let jsonData = JSON.parse(configurationValues); // <-- take note of this line
let resultList = jsonData.values.filter(value => value.city === 'chennai')

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

The Contains method of <arrayname> will never return true

Trying to randomly generate playing cards: class Card { private string face; private string suit; //Creating a card public Card() { string[] faceArray = {"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight" ...

Divide the identical elements and distinct elements from a provided array into two separate arrays storing unique elements and recurring elements

Can anyone help me with this query? I have an array of objects that need to be separated into repeating and non-repeating objects based on the segments they belong to, each in a separate array. For example- [ {name:"abc",id:1,segments:[1,2]}, {n ...

Determine the coordinates of points within a circle using Java programming

Discover this intriguing website where you can test your ability to draw a perfect circle. Intrigued by this, I decided to create a compact Java application that draws a circle from the center of your screen: // behold, my extensive array private ...

Angular Link Panel

I'm working on a marketplace app and I need to display a picture and name of a product when someone shares a link. Similar to how social media posts include a picture and title when shared. Can this be achieved using Angular, and if so, what steps do ...

A loop in JavaScript/TypeScript that runs precisely once every minute

Here is a snippet of my code: async run(minutesToRun: number): Promise<void> { await authenticate(); await this.stock.fillArray(); await subscribeToInstrument(this, this.orderBookId); await subscribeToOrderbook(this, this.orderBookId ...

Could I possibly incorporate @mui/material into an Angular project?

Is it possible to use npm install @mui/material in Angular? I am new to Angular and unsure if this will work. If not, are there any alternative Angular libraries that offer Material UI compatibility? ...

How can I cut an array by value in Vue?

I am working on a component that has a list of objects and I need to implement functionality where, when toggled, the objects' title prop is either added to or removed from an array. Adding the value was easy to do, but removing it has proven challeng ...

The element ''ag-grid-angular'' is unrecognized:

After using ag-grid successfully for a few months, I attempted to integrate a grid from a previous project into an Angular template like the one found in ngx-admin: ngx-admin This is how the template is structured: https://i.sstatic.net/Mfjw8.png I tr ...

Develop a filtering feature for your Django Rest Framework API

Models.py Categories: class Category_item(models.Model): item_category = models.CharField(max_length=200, unique=True) def __str__(self): return self.item_category Items: class Inventory(models.Model): category_item = models.ForeignK ...

Saving the state of checkboxes in Angular Material

I am trying to figure out a solution for storing checkbox values, specifically whether they have been checked before or not. For example, I have this dialog: https://i.sstatic.net/c16Ju.jpg After clicking on a checkbox and then clicking Save, the checkbox ...

Angular script error when running 'npm run' on select computers causing Unix command issues for some users but not all

Recently, I've encountered a puzzling issue at my workplace that has been difficult to diagnose. We utilize scripts in npm within the Angular framework to launch a local server instance. Strangely enough, some of my colleagues' computers are thro ...

Grab specific elements from an array and convert them into JSON format using PHP

I've encountered this issue multiple times but haven't been able to find a solution that works for my specific situation. Here is the array I am working with: $request=Array ( [0] => Array ( [staName] => Auditorium Stravinsky 2m2 ...

json remove unnecessary detailed timestamps

I need to develop a service that only returns JSON with date, time, and minutes, but the current implementation is displaying everything including milliseconds and seconds in the timestamp. How can I remove the milliseconds and seconds from the output? Be ...

methods for sharing real-time data between parent and child components in Angular versions 2 and above

When working with Angular, we are familiar with parent to child communication using the @Input decorator. However, the challenge arises when we need to pass dynamic data from the parent to the child component. Imagine having a 'name' property def ...

Guide on transferring a JSON to an ASP.NET API Controller from an Android Studio application

Creating a new app has been an exciting project for me. The app requires users to input various information such as their name and age into text fields. Once the user clicks a button, the data is sent to my API controller where the put method saves it in a ...

How can I retrieve all values that share the same reference number as an object in a JSON file using iOS and Objective-C?

This is an excerpt from the JSON response received from a web service. - Books :[ -{ RfNo:"1", SegOrd:"1", LegNo:"1", Title:"Wild Elephants", Author:"Dr. Vijitha Perera", Country:"Sri Lanka", Price:"$8.99" }, -{ ...

Angular2 material dropdown menu

Currently, I am studying angular2 with its material design. One of the modules I am using is md-select for material and here is a snippet of my code: <md-select> <md-option value="1">1</md-option> <md-option value="2">2< ...

Looking for an effortless distributed database that effortlessly stores basic JSON structures?

I have a relatively straightforward system that consists of hundreds of thousands of small and simple JSON documents. I am considering transitioning from mysql to a distributed system for added redundancy and backup capabilities. The current platform is d ...

The type 'GetServerSidePropsContext<ParsedUrlQuery, PreviewData>' does not include property X

My current setup includes: type Session = { bearer: string, firstName: string, lastName: string, etc... }; interface ServerContext extends GetServerSidePropsContext { session: Session, }; export type ServerProps<P extends { [key: string]: ...

I'm looking for a way to convert an array value to JSON using jQuery

i need assistance in converting an array value into json format. An example is provided below: Sample Array [Management Portal!@!@Production Issue Handling!@!@/IONSWeb/refDataManagement/searchDynamicScripts.do, Management Portal!@!@ Event Browser!@!@/ION ...