How to Read values from nested json objects in the config.json file with the help of config service class

Published

This is my config.json File

   {
     "timeout":10000
     
     "Status":{
         "Error":{"message":"Runtime","continue":False}
     }
   }

And below is the config service class

export class ConfigService {
  
  private config: Object = null;
    constructor(private http: HttpClient) {}
  

    public getConfig(key:any){
      return this.config[key];
    }


    public loadConfig() {
      return this.http
          .get<Config>('../configuration/config.json')
        .toPromise()
        .then(Configdata => {
          this.config = Configdata;
          console.log("error duration:",Configdata);
        });
    }
   
   
  }

First I want to read the value "Error" and the the value "False" and assign them to two different variables.That is,
Parameter1 = Error and
Parameter2 = false

I tried as,

let Parameter1=this.config.getConfig('Status');

then it reads,

    Status:
continue: false
message: "Runtime"

But I dont get the expected output.As I want to read only the value "Error" for Parameter1

How can I read those two values from the config.json file.

Any help is appreciated.
Thankyou.

Source: Angular Questions

Published
Categorized as angular, config.json, nested-object Tagged , ,

Answers

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq