how to format json in angular

I want to know how to format my json to have key and value using typescript with Angular framework,

with the current method if I use the keyvalue pipe in my html it will work but I want to format the json.

In my example below I have my Current json and the expected json so that you can see the result I expect and to be as clear as possible being a beginner in the business I wanted to be clear

Current.json

{
  "url": "url test"
  "flight": [
   [
    "1", 
    "apollo",
    "ariane"
   ],
   [
    "2",
    "Space X",
    "Boca chica"
   ]
  ]
}

expected.json // this json is what I would like to have

{
      "url": "url test"
      "flight": [
       [
        id: "1", 
        name: "apollo",
        rocket:"ariane"
       ],
       [
        id: "2",
        name: "Space X",
        rocket: "falcon 9"
       ]
      ]
    }

ts.file

get() {
 this.service.get().subscribe((data: Interface[])=> {
  this.array = data
 });


Read more here: https://stackoverflow.com/questions/68461220/how-to-format-json-in-angular

Content Attribution

This content was originally published by herve at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: