How can I access the keys with incorrect values in the JSON data using Angular 5 or TypeScript?

Is there a way to extract the keys with false values within this specified JSON?

xyz: any = {
    abc: {
      'a': true,
      'b': true,
      'c': true,
      'd': false,
      'e': {
        'f': true,
        'g': false
      },
      'h': true,
      'i': true
    }
}

Answer №1

Although it may not be the most visually appealing, this code snippet is designed to return all keys with a value of false from the given object.

xyz = {
    abc: {
      'a': true,
      'b': true,
      'c': true,
      'd': false,
      'e': {
        'f': true,
        'g': false
      },
      'h': true,
      'i': true
    }
}

function getFalseValues(obj, out) {
  Object.keys(obj).forEach(function(el) {
    if(obj[el] === false){
      out.push(el);
    }
    if (typeof obj[el] === "object") {
      getFalseValues(obj[el], out);
    }
  });
}

let output = [];
getFalseValues(xyz, output);

console.log(output);

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

What is the best way to extract properties from JSON data using Javascript?

The json output provided is as follows: { "categories":[ "Physical support- 18-64 (RA)" ], "series":[ { "name":"Buckinghamshire", "data":[ 9088 ] }, { "name":"Lincolnshire", ...

Encountering a java heap space exception while attempting to process massive JSON data with Spring RestTemplate

Currently, I am utilizing Resttemplate to consume a large JSON from an external server. The code functions as expected with smaller datasets; however, when tested against the full dataset, I encounter difficulties mapping the response to the bean class. Be ...

Displaying the output of an API call using the `print_r()` function

Currently, I'm attempting to capture a value from the response but I'm unsure of the correct method to do so. When I use print_r() on the array, it outputs the following: stdClass Object ( [user_id] => id number [access_token] => access to ...

problem occurs when transferring data to onActivityResult

In my coding journey, I am facing a challenge with sending a string from one activity to the main activity of my project. I have successfully created an object within the onActivityResult section of my code, but I encounter a "resource not found" exception ...

Combining two sets of data into JSON format

I've developed a PHP-based API to manage data requests from a MySQL database. Currently, I'm facing an issue with select query A that returns a JSON object to the API caller: <pre> $queryA = "SELECT ..."; $queryB = "SELECT ..."; $a ...

I attempted to unsubscribe from an observable in Angular, but I encountered an error stating that the unsubscribe function does not exist

Here is the code snippet from a components.ts file in an Angular project. I encountered the following error during compilation: ERROR merge/merge.component.ts:75:12 - error TS2551: Property 'unsubscribe' does not exist on type 'Observable& ...

converting a JSON object into a string on an Android device

I've attempted various methods to parse a JSON object, but I'm struggling to find a solution. Here is the JSON string I am working with: { "JSONDataResult": {"Messages": [{ "Id":"0", "Categor ...

Steps to resolve the error message 'Argument of type 'number' is not assignable to parameter of type 'string | RegExp':

Is there a way to prevent users from using special symbols or having blank spaces without any characters in my form? I encountered an error when trying to implement this in my FormGroup Validator, which displayed the message 'Argument of type 'nu ...

Tips for verifying the results of a specific element on a webpage using Angular

Hello all, I am currently learning Angular and facing an issue related to components. I have successfully created a component named "test". When I execute the code, I get the desired output. However, if I remove the tag from app.component.html, I end up ...

Using a SharedModule in Angular2: A Guide

I have a single Angular2 component that I need to utilize across multiple modules. To achieve this, I created a SharedModule as shown below: import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-bro ...

Store the information retrieved from an API request in a model using JSON format

Recently, I've been diving into the world of making API calls and handling JSON responses to display specific data in my app. Now, I'm looking to take this data a step further by saving it to a model for future use. My goal is to click a button ...

Dealing with Json parsing and NullPointerExceptions in Gson library on Android platform

I'm new to using StackOverflow for posting inquiries. After conducting extensive research, I have not been able to find a solution that addresses my specific issue. My current challenge involves parsing a Json file from the following URL: https://aja ...

Just a single array in a basic JSON file for integration into my Android application

I'm dealing with a JSON file that contains a single unnamed array, like this: ["Cream","Cheese","Milk","Powder Milk","Blue Cheese","Gouda Cheese"] How can I extract this array and store it in an array or ArrayList in my Android Studio project? An ...

The specified file cannot be found within the Node file system

I am working on a project that involves reading a file using Node fs, and I have the following code: const files: FileSystemTree = { "Component.tsx": { file: { contents: fs.readFileSync( `../../apps/components ...

Incrementing values in ng-repeat object automatically

My project involves extracting game information from mlb.com and utilizing angularjs along with the ng-repeat directive to display it. A sample of the JSON feed is shown below. { "data": { "games": { "next_day_date": "2017-08-19", "mo ...

What could be causing mongoexport to generate incorrectly formatted JSON?

After exporting my mongo collections, I encountered an issue when trying to import them. MongoDB kept saying that the JSON format was malformed. Unexpected end of JSON input When running the data through a JSON validator, I received the following error m ...

There seems to be an issue with parsing the JSON data due to a

Currently, I am in the process of learning about the JSON Parser. I have been following a tutorial on androidhive and attempted to replicate their code. However, I encountered some errors along the way, such as: 11-22 17:27:12.132: E/AndroidRuntime(1938) ...

Leveraging JSON information to establish variables within a servlet

After searching extensively, I couldn't find any tutorials that addressed my specific issue, so I've decided to seek help by posting my question here. I have a poll.json file: { "poll": { "title": "About your preferences", " ...

Unexpected issues arise with as3corelib serialization

Encountering an error. Error #2099: The loading object is not sufficiently loaded to provide this information Whenever I attempt to convert an object into JSON using as3corelib, I face the above error message. Encoding a value object without any parent ...

Ember - connecting to a JSON data source

Recently, I have been following a tutorial/example from codeschool and everything is going well. However, the example code includes the line: App.ApplicationAdapter = DS.FixtureAdapter.extend(); Now, I want to maintain all the existing functionality but ...