Get JSON data by ID

I’m trying to get data from a particular ID in a JSON file.

The JSON set-up is:

{
    "items": [
      {
      "id":"0",
      "link": "/music",
      "title": "Music",
      "area": "Devon",
      "type": "place",
      "image": ""
    },
    {
       "id":"1",
      "link": "/festivals",
      "title": "Festivals",
      "area": "Cornwall",
      "type": "event",
      "image": ""
    },

Each page needs to get different data. So far I have done this (page.ts) which gets all the json data

 this.http.get('assets/events.json').subscribe(res => {
      this.information = res['items']

But I need to add a filter to get the ID and then get the data from that ID only. I found this (below) but have no idea how to implement it.

 const index = this.information.findIndex(item => item.id === 8);

Any help appreciated

I work backwards in cases like this. What does our page want? It wants to provide an id and get a Happening (call it whatever you like, I use this name to avoid conflicts with Event, which is used all over DOM). Write a service that provides this:

interface Happening {
  id: string;
  link: string;
  ...
}

interface SadlyNamedResponse {
  items: Happening[];
}

class HappeningService {
  constructor(private http: HttpClient) {}

  allHappenings(): Observable<Happening[]> {
    return this.http.get<SadlyNamedResponse>(...)
      .pipe(map(rsp => rsp.items));
   }

  happeningById(wantedId: string): Observable<Happening | null> {
    return this.allHappenings()
      .pipe(map(haps => {
         for (let hap of haps) {
           if (hap.id === wantedId) {
             return hap;
           }
         }
         return null;
       }));
  }
}

class Page {
  constructor(private happer: HappeningService) {
  }

  howeverIdIsDetermined(id: string) {
    this.happer.happeningById(id).subscribe(hap => { /* whee */ });
  }
}

I imagine that your object looks like this:

this.information = {
    "items": [
      {
      "id":"0",
      "link": "/music",
      "title": "Music",
      "area": "Devon",
      "type": "place",
      "image": ""
    },
    {
       "id":"1",
      "link": "/festivals",
      "title": "Festivals",
      "area": "Cornwall",
      "type": "event",
      "image": ""
    },
]
 }

To get the object with the required ID, all you need to do is something like this:

for(let i = 0 ; i < this.information.items.length ;i++){
    
    var innerObject = this.information.items[i]
//finding object where id is equal to 1
    if(innerObject.id === '1'){
      return innerObject
    }
  }
  return null;

Also, keep in mind that the id value is a string, not an integer.

Ok those are really helpful, thank you.