There is a json data file named dummy, with the following structure:
[
{"key":"KEY1", "value":["alpha","beta","gamma"]},
{"key":"KEY2", "value":["A","B","C"]},
{"key":"KEY3", "value":["One","Foo","Bar"]}
]
The goal is to convert this json file into a map with key-value pairs matching the structure of the json file.
To accomplish this task, an observable named myObservable was created. Below is an example code snippet from the component.ts file:
myMap: any = {};
myObservable: Observable<any> = Observable.of(this.dummy);
getObservable() {
return this.myObservable;
}
ngOnInit() {
this.getObservable()
.subscribe(myResponse => {
this.myMap = new Map(myResponse); //Converting myresponse to map here.
)}.
Unfortunately, the above approach did not work as intended. How can I correctly convert this observable object to a map in TypeScript?
Desired Output:
{
Key1,[alpha,beta,gamma]
Key2,[A,B,C]
Key3,[One,Foo,Bar]
}