My goal is to extract data from a local JSON file and store it in an array of InputData type objects. The JSON contains multiple entries, each following the structure of InputData. I attempted to achieve this with the code snippet below.
The issue arises when trying to subscribe, resulting in the error message "TS2339: Property 'subscribe' does not exist on type '{}'."
If subscribing to the JSON is not possible, what alternative approach can be taken to read the entries and populate the array?
import dataset from "dataset.json";
export interface InputData {
_id: {
$oid: String;
};
id: String;
expNumber: Number;
passed: Boolean;
}
@Component({
selector: "app-read-data",
templateUrl: "./read-data.component.html",
styleUrls: ["./read-data.component.scss"],
})
export class ReadDataComponent implements OnInit {
public data:InputData[];
constructor() {}
ngOnInit(): void {
this.dataset.subscribe(readData => {
readData.reduce(t => this.data.push(t));
});
console.log("DATA", this.data);
}
Below is an example of the JSON File:
[{
"_id": {
"$oid": "51275"
},
"id": "T22F2r",
"expNumber": 2,
"passed": false
},{
"_id": {
"$oid": "23451"
},
"id": "r3322F",
"expNumber": 2,
"passed": true
}]