How i can output this as JSON?

How can I output the following data (see Picture below, blue arrow)

as a JSON array like:
{
“name”: “John”,
“title”:30,
“phone”: “+39493849”
}
I have tried JSON.stringify

here is my .ts:

public createQRcode(item: Vkarten){
  this.visitenkarteService.getItems().then(items => {
    let result: any;
    result = [
      item.title,
      item.name,
      item.telefon
    ];
    this.createCode = JSON.stringify(result);
  });
  this.mylist.closeSlidingItems();
  this.loadItems();
}

i tried to take item instead of result, but i get then to much information that i dont want.
here is my .html:

  <ion-list #mylist>

    <ion-list-header>
      <ion-label>Meine Visitenkarten (Um zu Löschen,Upzudaten oder QR-Code zu generieren nach links Sliden!)</ion-label>
    </ion-list-header>

    <ion-item-sliding *ngFor="let item of items">
      
      <ion-item color="light">
        <ion-label text-wrap>
          <h3>{{ item.title }}</h3>
          <p>{{ item.name }}</p>
          <ion-text color="secondary">
          <p>{{ item.telefon }}</p>
          </ion-text>
          <p>{{ item.modified | date:'short'}}</p>
        </ion-label>
      </ion-item>

      <ion-item-options side="end">
        <ion-item-option color="secondary" (click)="updateItem(item)">Update</ion-item-option>
        <ion-item-option color="danger" (click)="deleteItem(item)">Delete</ion-item-option>
        <ion-item-option color="primary" (click)="createQRcode(item)">Generate QR</ion-item-option> 
      </ion-item-options>
    </ion-item-sliding>
  </ion-list>

here is Vkarten:

export interface Vkarten {
    id: number;
    name: number;
    title: string;
    telefon: number;
   modified: number;
}

if you need something else, tell me

i hope this is not a stupid question, it would help me a lot if you could give me a tutorial or a topic how i should proceed.

Result={ title:item.title, name:item.title Etc…}

Question isn’t stupid. Figuring the answer will make u feel that way in hindsight :crazy_face::crazy_face:

Besides, there is more going on that u may need to fix (like the array items) and addressing the items in the qr array

1 Like

I haven’t had a chance to flog this post in several years, but it might be time to dust it off.

1 Like